You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: introduce getClaims method to verify asymmetric JWTs (#1030)
## What kind of change does this PR introduce?
* `getClaims` supports verifying JWTs (both asymmetric and symmetric)
and returns the entire set of claims in the JWT payload
---------
Co-authored-by: Stojan Dimitrovski <[email protected]>
polyfillGlobalThis()// Make "globalThis" available
106
112
@@ -140,7 +146,10 @@ export default class GoTrueClient {
140
146
protectedstorageKey: string
141
147
142
148
protectedflowType: AuthFlowType
143
-
149
+
/**
150
+
* The JWKS used for verifying asymmetric JWTs
151
+
*/
152
+
protectedjwks: {keys: JWK[]}
144
153
protectedautoRefreshToken: boolean
145
154
protectedpersistSession: boolean
146
155
protectedstorage: SupportedStorage
@@ -220,7 +229,7 @@ export default class GoTrueClient {
220
229
}else{
221
230
this.lock=lockNoOp
222
231
}
223
-
232
+
this.jwks={keys: []}
224
233
this.mfa={
225
234
verify: this._verify.bind(this),
226
235
enroll: this._enroll.bind(this),
@@ -1288,17 +1297,6 @@ export default class GoTrueClient {
1288
1297
}
1289
1298
}
1290
1299
1291
-
/**
1292
-
* Decodes a JWT (without performing any validation).
1293
-
*/
1294
-
private_decodeJWT(jwt: string): {
1295
-
exp?: number
1296
-
aal?: AuthenticatorAssuranceLevels|null
1297
-
amr?: AMREntry[]|null
1298
-
}{
1299
-
returndecodeJWTPayload(jwt)
1300
-
}
1301
-
1302
1300
/**
1303
1301
* Sets the session data from the current session. If the current session is expired, setSession will take care of refreshing it to obtain a new session.
1304
1302
* If the refresh token or access token in the current session is invalid, an error will be thrown.
@@ -1328,7 +1326,7 @@ export default class GoTrueClient {
thrownewAuthInvalidJwtError('No matching signing key found in JWKS')
2628
+
}
2629
+
returnjwk
2630
+
}
2631
+
2632
+
/**
2633
+
* @experimental This method may change in future versions.
2634
+
* @description Gets the claims from a JWT. If the JWT is symmetric JWTs, it will call getUser() to verify against the server. If the JWT is asymmetric, it will be verified against the JWKS using the WebCrypto API.
0 commit comments