-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add credentials()
and hasValidCredentials()
[SDK-3997]
#207
Conversation
1502c1a
to
ce8b29b
Compare
const JWTDecodeException.invalidPartCount(final String jwt, final int parts) | ||
: this(JWTDecodeException._invalidPartCount, | ||
'The JWT $jwt has $parts parts when it should have 3 parts.'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are the same messages and error cases as the ones in JWTDecode.swift: https://github.com/auth0/JWTDecode.swift/blob/master/JWTDecode/JWTDecodeError.swift
fb35de0
to
66dec78
Compare
accessToken: webCredentials.access_token, | ||
expiresAt: expiresAt, | ||
user: user, | ||
tokenType: 'Bearer'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we get tokenType
from the getTokenSilently
detailed response - should we use that, or hard code it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not part of TokenEndpointResponse
: https://github.com/auth0/auth0-spa-js/blob/master/src/global.ts#L500
static Map<String, dynamic> decode(final String jwt) { | ||
final parts = jwt.split('.'); | ||
|
||
if (parts.length != 3) { | ||
throw JWTDecodeException.invalidPartCount(jwt, parts.length); | ||
} | ||
|
||
final String stringPayload; | ||
|
||
try { | ||
final decodedPayload = base64.decode(base64.normalize(parts[1])); | ||
stringPayload = utf8.decode(decodedPayload); | ||
} catch (error) { | ||
throw JWTDecodeException.invalidBase64URL(parts[1]); | ||
} | ||
|
||
try { | ||
return jsonDecode(stringPayload) as Map<String, dynamic>; | ||
} catch (error) { | ||
throw JWTDecodeException.invalidJSON(parts[1]); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can already get the decoded token from the SDK using getIdTokenClaims
- do we need to decode it manually here?
https://auth0.github.io/auth0-spa-js/classes/Auth0Client.html#getIdTokenClaims
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure we can represent custom claims (https://github.com/auth0/auth0-spa-js/blob/master/src/global.ts#L578) without decoding to a Map<String, dynamic>
, hence the custom decoding.
📋 Changes
This PR adds support for fetching the credentials, and for checking if there are any valid credentials stored. The following public methods were added:
credentials()
-> callsgetTokenSilently()
from the SPA SDK.hasValidCredentials()
-> callsisAuthenticated()
from the SPA SDK.🎯 Testing
The changes were tested manually. Unit tests will be added in a future PR.
Screen.Recording.2023-02-26.at.22.21.21.mov