mirror of
https://github.com/djdevin/recflare.git
synced 2026-09-08 14:41:28 -07:00
clean up auth, some storage improvements
This commit is contained in:
@@ -102,14 +102,7 @@ async function placeNewPlayerInOrientation(env: App['Bindings'], accountId: numb
|
||||
|
||||
/** The Bearer token's account id (`sub`), or null when there's no valid token. */
|
||||
async function authedId(c: Context<App>): Promise<number | null> {
|
||||
const authHeader = c.req.header('Authorization') ?? ''
|
||||
if (!authHeader.toLowerCase().startsWith('bearer ')) return null
|
||||
const sub = await validateAndGetAccountId(
|
||||
authHeader.slice('Bearer '.length),
|
||||
await c.env.JWT_SECRET.get()
|
||||
)
|
||||
const id = sub ? Number.parseInt(sub, 10) : Number.NaN
|
||||
return Number.isNaN(id) ? null : id
|
||||
return validateAndGetAccountId(c.req.raw, await c.env.JWT_SECRET.get())
|
||||
}
|
||||
|
||||
const app = new Hono<App>()
|
||||
|
||||
@@ -143,8 +143,8 @@ describe('auth worker routes', () => {
|
||||
)
|
||||
) as Record<string, unknown>
|
||||
expect(payload.sub).toBe('42') // account_id from the body is honored
|
||||
expect(payload.iss).toBe('https://auth.lapis.codes')
|
||||
expect(payload.aud).toBe('https://auth.lapis.codes/resources')
|
||||
expect(payload.iss).toBe('https://auth.recflare.net')
|
||||
expect(payload.aud).toBe('https://auth.recflare.net')
|
||||
expect(payload.role).toContain('gameClient')
|
||||
expect(payload.scope).toContain('rn.api')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user