-
Notifications
You must be signed in to change notification settings - Fork 66
Fix Issues with verifyIdToken #58
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
1981f22
update token_verifier to match node admin-sdk
jtdLab f2d9a30
fix token verification for emulator
jtdLab b0c844c
test: add decode id token test
jtdLab 8cab3de
refactor: simplify by readding verifyJwtSignature
jtdLab c37a01f
fix: dont catch all errors when using emulator e.g expired should sti…
jtdLab a6d1436
test: remove uid
jtdLab 7cda879
Update packages/dart_firebase_admin/lib/src/auth/token_verifier.dart
jtdLab 09307f9
Merge branch 'main' into main
rrousselGit 4780709
Refactor
rrousselGit 45a45d2
ignores
rrousselGit bd89ab9
Add regression test
rrousselGit 3fcdbf7
Remove test
rrousselGit 68982f7
Merge branch 'main' into main
rrousselGit a34e288
env
rrousselGit d6e1bf7
Merge branch 'main' of https://github.com/jtdlab/dart_firebase_admin …
rrousselGit cfcbb2e
CI
rrousselGit 2f16858
C
rrousselGit cd3c478
C
rrousselGit 0db9503
C
rrousselGit 6c0a8ec
A
rrousselGit 4fce995
X
rrousselGit 0a66710
A
rrousselGit 70db525
Use Env
rrousselGit 16d0f3d
a
rrousselGit e4c3f23
A
rrousselGit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,14 +9,28 @@ class EmulatorSignatureVerifier implements SignatureVerifier { | |
| @override | ||
| Future<void> verify(String token) async { | ||
| // Signature checks skipped for emulator; no need to fetch public keys. | ||
|
|
||
| try { | ||
| verifyJwtSignature( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would recommend maybe keeping the |
||
| JWT.verify( | ||
| token, | ||
| SecretKey(''), | ||
| ); | ||
| } on JWTExpiredException catch (e, stackTrace) { | ||
| Error.throwWithStackTrace( | ||
| JwtError( | ||
| JwtErrorCode.tokenExpired, | ||
| 'The provided token has expired. Get a fresh token from your ' | ||
| 'client app and try again.', | ||
| ), | ||
| stackTrace, | ||
| ); | ||
| } on JWTInvalidException catch (e) { | ||
| // Emulator tokens have "alg": "none" | ||
| if (e.message == 'unknown algorithm') return; | ||
| if (e.message == 'invalid signature') return; | ||
| rethrow; | ||
| } catch (_) { | ||
| // Invalid signature. Can be ignored when using emulator. | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -122,11 +136,32 @@ class PublicKeySignatureVerifier implements SignatureVerifier { | |
| 'no-matching-kid-error', | ||
| ); | ||
| } | ||
| verifyJwtSignature( | ||
| token, | ||
| RSAPublicKey.cert(publicKey), | ||
| issueAt: Duration.zero, // Any past date should be valid | ||
| ); | ||
|
|
||
| try { | ||
| JWT.verify( | ||
| token, | ||
| RSAPublicKey.cert(publicKey), | ||
| issueAt: Duration.zero, // Any past date should be valid | ||
| ); | ||
| } on JWTExpiredException catch (e, stackTrace) { | ||
| Error.throwWithStackTrace( | ||
| JwtError( | ||
| JwtErrorCode.tokenExpired, | ||
| 'The provided token has expired. Get a fresh token from your ' | ||
| 'client app and try again.', | ||
| ), | ||
| stackTrace, | ||
| ); | ||
| } catch (e, stackTrace) { | ||
| Error.throwWithStackTrace( | ||
| JwtError( | ||
| JwtErrorCode.invalidSignature, | ||
| 'Error while verifying signature of Firebase ID token: $e', | ||
| ), | ||
| stackTrace, | ||
| ); | ||
| } | ||
|
|
||
| // At this point most JWTException's should have been caught in | ||
| // verifyJwtSignature, but we could still get some from JWT.decode above | ||
| } on JWTException catch (e) { | ||
|
|
@@ -140,46 +175,6 @@ class PublicKeySignatureVerifier implements SignatureVerifier { | |
|
|
||
| sealed class SecretOrPublicKey {} | ||
|
|
||
| @internal | ||
| void verifyJwtSignature( | ||
| String token, | ||
| JWTKey key, { | ||
| Duration? issueAt, | ||
| Audience? audience, | ||
| String? subject, | ||
| String? issuer, | ||
| String? jwtId, | ||
| }) { | ||
| try { | ||
| JWT.verify( | ||
| token, | ||
| key, | ||
| issueAt: issueAt, | ||
| audience: audience, | ||
| subject: subject, | ||
| issuer: issuer, | ||
| jwtId: jwtId, | ||
| ); | ||
| } on JWTExpiredException catch (e, stackTrace) { | ||
| Error.throwWithStackTrace( | ||
| JwtError( | ||
| JwtErrorCode.tokenExpired, | ||
| 'The provided token has expired. Get a fresh token from your ' | ||
| 'client app and try again.', | ||
| ), | ||
| stackTrace, | ||
| ); | ||
| } catch (e, stackTrace) { | ||
| Error.throwWithStackTrace( | ||
| JwtError( | ||
| JwtErrorCode.invalidSignature, | ||
| 'Error while verifying signature of Firebase ID token: $e', | ||
| ), | ||
| stackTrace, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /// Jwt error code structure. | ||
| class JwtError extends Error { | ||
| JwtError(this.code, this.message); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Since behavior changed here, would you mind writing a test?