few fixes

This commit is contained in:
Hailey
2024-04-15 00:42:22 -07:00
parent 2c1b3709af
commit 9f6db0ef67
2 changed files with 7 additions and 6 deletions
@@ -19,11 +19,7 @@ export class ReactNativeKey extends Key {
// Note: OauthClientReactNative.generatePrivateJwk should throw if it
// doesn't support the algorithm.
const res = await OauthClientReactNative.generateJwk(algo)
const jwk = jwkValidator.parse({
...res.privateKey,
key_ops: ['sign', 'verify'],
kid,
})
const jwk = res.privateKey
const use = jwk.use || 'sig'
return new ReactNativeKey(jwkValidator.parse({...jwk, use, kid}))
} catch {
@@ -44,12 +40,15 @@ export class ReactNativeKey extends Key {
>(token: Jwt, options?: VerifyOptions<C>): Promise<VerifyResult<P, C>> {
const result = await OauthClientReactNative.verifyJwt(token, this.jwk)
// TODO see if we can make these `undefined` or maybe update zod to allow `nullable()`
let payloadParsed = JSON.parse(result.payload)
payloadParsed = Object.fromEntries(
Object.entries(payloadParsed as object).filter(([_, v]) => v !== null),
)
const payload = jwtPayloadSchema.parse(payloadParsed)
// We don't need to validate this, because the native types ensure it is correct. But this is a TODO
// for the same reason above
const protectedHeader = result.protectedHeader
if (options?.audience != null) {
+2
View File
@@ -69,6 +69,8 @@ function HomeScreenReady({
)
const verified = await key.verifyJwt(jwt)
console.log(verified)
})()
}, [])