chadtmiller.com/knotless
git that lives in your Atmosphere account
1
10
The harness approves a login with the Referer a browser sends
harness/authorize.mjs+8−2
| @@ -32,6 +32,12 @@ const [username, password, url] = args.filter((a) => !['--reject', '--create'].i | ||
const authorize = new URL(url) | ||
const origin = authorize.origin | ||
const api = `${origin}/@atproto/oauth-provider/~api` | ||
// The Referer a browser sends from the authorization page: Chrome and | ||
// Firefox cut one longer than 4096 bytes to its origin, which the | ||
// provider refuses ("Invalid referer"), as a client ID that carries a long | ||
// scope makes the page's URL. | ||
const REFERER_LIMIT = 4096 | ||
const referer = authorize.href.length > REFERER_LIMIT ? `${origin}/` : authorize.href | ||
| ||
const jar = new Map() | ||
const cookies = () => | ||
| @@ -93,7 +99,7 @@ const call = async (endpoint, body, token) => { | ||
'sec-fetch-mode': 'same-origin', | ||
'sec-fetch-site': 'same-origin', | ||
origin, | ||
referer: authorize.href, | ||
referer, | ||
'x-csrf-token': jar.get('csrf-token'), | ||
cookie: cookies(), | ||
}, | ||
| @@ -131,7 +137,7 @@ const back = await send(done.url, { | ||
'sec-fetch-mode': 'navigate', | ||
'sec-fetch-dest': 'document', | ||
'sec-fetch-site': 'same-origin', | ||
referer: authorize.href, | ||
referer, | ||
cookie: cookies(), | ||
}, | ||
}) | ||