Repository navigation
feat(pnv): reject test tokens by default and add PhoneNumberVerificationTokenOptions #3293
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -73,12 +73,34 @@ export interface PhoneNumberVerificationToken { | |||||||||||
| */ | ||||||||||||
| phoneNumber: string; | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Indicates whether the token was issued while the app was in test mode. | ||||||||||||
| * This value is not actually one of the JWT token claims. It is added as a | ||||||||||||
| * convenience, and is set to `true` when the `"test_number"` claim is | ||||||||||||
| * `true`, or `false` otherwise. | ||||||||||||
| */ | ||||||||||||
| testNumber: boolean; | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Other arbitrary claims included in the token. | ||||||||||||
| */ | ||||||||||||
| [key: string]: any; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Interface representing options for the {@link PhoneNumberVerification.verifyToken} method. | ||||||||||||
| */ | ||||||||||||
| export interface PhoneNumberVerificationTokenOptions { | ||||||||||||
|
Member
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. Could we get a TW review on the new docstrings?
Author
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. Asked @kevinthecheung to do a TW pass on the new TSDoc comments. |
||||||||||||
| /** | ||||||||||||
| * To accept test-mode tokens (tokens containing the claim `"test_number": true`), | ||||||||||||
| * set this option to `true`. By default, {@link PhoneNumberVerification.verifyToken} | ||||||||||||
| * rejects test-mode tokens. | ||||||||||||
|
Comment on lines
+95
to
+97
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.
Suggested change
|
||||||||||||
| * | ||||||||||||
| * Enable this option only during development and testing. | ||||||||||||
| */ | ||||||||||||
| acceptTestTokens?: boolean; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| export { | ||||||||||||
| PhoneNumberVerificationErrorCode, | ||||||||||||
| FirebasePhoneNumberVerificationError, | ||||||||||||
|
|
||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,7 +16,10 @@ | |||||||
| */ | ||||||||
|
|
||||||||
| import { App } from '../app'; | ||||||||
| import { PhoneNumberVerificationToken } from './phone-number-verification-api'; | ||||||||
| import { | ||||||||
| PhoneNumberVerificationToken, | ||||||||
| PhoneNumberVerificationTokenOptions, | ||||||||
| } from './phone-number-verification-api'; | ||||||||
| import { PhoneNumberTokenVerifier } from './token-verifier'; | ||||||||
| import { JWKS_URL, FPNV_TOKEN_INFO } from './phone-number-verification-api-client-internal'; | ||||||||
|
|
||||||||
|
|
@@ -53,13 +56,20 @@ export class PhoneNumberVerification { | |||||||
| } | ||||||||
|
|
||||||||
| /** | ||||||||
| * Verifies a Firebase Phone Number Verification token. | ||||||||
| * Verifies a Firebase Phone Number Verification token. By default, tokens issued in | ||||||||
| * test mode (containing `"test_number": true`) are rejected unless | ||||||||
| * `options.acceptTestTokens` is set to `true`. | ||||||||
| * | ||||||||
| * @param jwt - A string containing the Firebase Phone Number Verification JWT. | ||||||||
| * @param options - Optional {@link PhoneNumberVerificationTokenOptions} object when verifying a | ||||||||
| * Phone Number Verification token. | ||||||||
|
Comment on lines
+64
to
+65
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.
Suggested change
|
||||||||
| * @returns A promise that resolves with the decoded token. | ||||||||
| */ | ||||||||
| public verifyToken(jwt: string): Promise<PhoneNumberVerificationToken> { | ||||||||
| return this.phoneNumberVerificationVerifier.verifyJWT(jwt); | ||||||||
| public verifyToken( | ||||||||
| jwt: string, | ||||||||
| options?: PhoneNumberVerificationTokenOptions | ||||||||
| ): Promise<PhoneNumberVerificationToken> { | ||||||||
| return this.phoneNumberVerificationVerifier.verifyJWT(jwt, options); | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
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.
If there is a test_number claim then isn't this basically one of the JWT token claims? I don't know that the caveat is helpful in this case