-
Notifications
You must be signed in to change notification settings - Fork 409
feat: add basic fpnv #3030
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
Open
boikoa-gl
wants to merge
9
commits into
firebase:fpnv
Choose a base branch
from
boikoa-gl:fpnv
base: fpnv
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: add basic fpnv #3030
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f603e65
feat: add basic fpnv
boikoa-gl 23868e8
chore: resolve comments
boikoa-gl 7f71eed
fix: remove unused interface
boikoa-gl 8413368
chore: update export
boikoa-gl e90c2bd
chore: linting
boikoa-gl 2a759df
chore: update export
boikoa-gl fabcf80
feat: add apidocs
boikoa-gl 38e5a17
chore: resolve commnets
boikoa-gl 71f48cb
chore: linting
boikoa-gl 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 |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| ## API Report File for "firebase-admin.fpnv" | ||
|
|
||
| > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). | ||
|
|
||
| ```ts | ||
|
|
||
| import { Agent } from 'http'; | ||
|
|
||
| // @public | ||
| export class Fpnv { | ||
| // Warning: (ae-forgotten-export) The symbol "App" needs to be exported by the entry point index.d.ts | ||
| get app(): App; | ||
| // Warning: (ae-forgotten-export) The symbol "FirebasePhoneNumberTokenVerifier" needs to be exported by the entry point index.d.ts | ||
| // | ||
| // (undocumented) | ||
| protected readonly fpnvVerifier: FirebasePhoneNumberTokenVerifier; | ||
| // (undocumented) | ||
| verifyToken(fpnvJwt: string): Promise<FpnvToken>; | ||
| } | ||
|
|
||
| // @public | ||
| export interface FpnvToken { | ||
| [key: string]: any; | ||
| aud: string[]; | ||
| exp: number; | ||
| getPhoneNumber(): string; | ||
| iat: number; | ||
| iss: string; | ||
| jti: string; | ||
| nonce: string; | ||
| sub: string; | ||
| } | ||
|
|
||
| // @public | ||
| export function getFirebasePnv(app?: App): Fpnv; | ||
|
|
||
| ``` | ||
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 |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /*! | ||
| * @license | ||
| * Copyright 2025 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { PrefixedFirebaseError } from '../utils/error'; | ||
|
|
||
| export interface FirebasePhoneNumberTokenInfo { | ||
| /** Documentation URL. */ | ||
| url: string; | ||
| /** verify API name. */ | ||
| verifyApiName: string; | ||
| /** The JWT full name. */ | ||
| jwtName: string; | ||
| /** The JWT short name. */ | ||
| shortName: string; | ||
| /** The JWT typ" (Type) */ | ||
| typ: string; | ||
| } | ||
|
|
||
| export const CLIENT_CERT_URL = 'https://www.googleapis.com/robot/v1/metadata/x509/[email protected]'; | ||
|
|
||
| export const PN_TOKEN_INFO: FirebasePhoneNumberTokenInfo = { | ||
| url: 'https://firebase.google.com/docs/phone-number-verification', | ||
| verifyApiName: 'verifyToken()', | ||
| jwtName: 'Firebase Phone Verification token', | ||
| shortName: 'FPNV token', | ||
| typ: 'JWT', | ||
| }; | ||
|
|
||
| export const FPNV_ERROR_CODE_MAPPING = { | ||
| INVALID_ARGUMENT: 'invalid-argument', | ||
| INVALID_TOKEN: 'invalid-token', | ||
| EXPIRED_TOKEN: 'expired-token', | ||
| } satisfies Record<string, FpnvErrorCode>; | ||
|
|
||
| export type FpnvErrorCode = | ||
| | 'invalid-argument' | ||
| | 'invalid-token' | ||
| | 'expired-token' | ||
|
|
||
| /** | ||
| * Firebase Phone Number Verification error code structure. This extends `PrefixedFirebaseError`. | ||
| * | ||
| * @param code - The error code. | ||
| * @param message - The error message. | ||
| * @constructor | ||
| */ | ||
| export class FirebaseFpnvError extends PrefixedFirebaseError { | ||
| constructor(code: FpnvErrorCode, message: string) { | ||
| super('fpnv', code, message); | ||
|
|
||
| /* tslint:disable:max-line-length */ | ||
| // Set the prototype explicitly. See the following link for more details: | ||
| // https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work | ||
| /* tslint:enable:max-line-length */ | ||
| (this as any).__proto__ = FirebaseFpnvError.prototype; | ||
| } | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /*! | ||
boikoa-gl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * @license | ||
| * Copyright 2025 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
|
|
||
| /** | ||
| * Interface representing a Fpnv token. | ||
| */ | ||
| export interface FpnvToken { | ||
| /** | ||
| * The issuer identifier for the issuer of the response. | ||
| * This value is a URL with the format | ||
| * `https://firebaseappcheck.googleapis.com/<PROJECT_NUMBER>`, where `<PROJECT_NUMBER>` is the | ||
| * same project number specified in the {@link FpnvToken.aud} property. | ||
| */ | ||
| iss: string; | ||
|
|
||
| /** | ||
| * The audience for which this token is intended. | ||
| * This value is a JSON array of two strings, the first is the project number of your | ||
| * Firebase project, and the second is the project ID of the same project. | ||
| */ | ||
| aud: string[]; | ||
|
|
||
| /** | ||
| * The Fpnv token's expiration time, in seconds since the Unix epoch. That is, the | ||
| * time at which this Fpnv token expires and should no longer be considered valid. | ||
| */ | ||
| exp: number; | ||
|
|
||
| /** | ||
| * The Fpnv token's issued-at time, in seconds since the Unix epoch. That is, the | ||
| * time at which this Fpnv token was issued and should start to be considered | ||
| * valid. | ||
| */ | ||
| iat: number; | ||
|
|
||
| /** | ||
| * The phone number of User. | ||
| */ | ||
| sub: string; | ||
|
|
||
| /** | ||
| * Unique ID. | ||
| */ | ||
| jti: string; | ||
|
|
||
| /** | ||
| * Unique ID. | ||
| */ | ||
| nonce: string; | ||
|
|
||
| /** | ||
| * The corresponding user's phone number. | ||
| * This value is not actually one of the JWT token claims. It is added as a | ||
| * convenience, and is set as the value of the {@link FpnvToken.sub} property. | ||
| */ | ||
| getPhoneNumber(): string; | ||
|
|
||
| /** | ||
| * Other arbitrary claims included in the token. | ||
| */ | ||
| [key: string]: any; | ||
| } | ||
|
|
||
| export { FpnvErrorCode, FirebaseFpnvError } from './fpnv-api-client-internal'; | ||
|
|
||
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 |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /*! | ||
| * @license | ||
| * Copyright 2025 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { App } from '../app'; | ||
| import { FpnvToken } from './fpnv-api'; | ||
| import { FirebasePhoneNumberTokenVerifier } from './token-verifier'; | ||
| import { CLIENT_CERT_URL, PN_TOKEN_INFO } from './fpnv-api-client-internal'; | ||
|
|
||
| /** | ||
| * Fpnv service bound to the provided app. | ||
| */ | ||
| export class Fpnv { | ||
| private readonly appInternal: App; | ||
| protected readonly fpnvVerifier: FirebasePhoneNumberTokenVerifier; | ||
|
|
||
boikoa-gl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /** | ||
| * @param app - The app for this `Fpnv` service. | ||
| * @constructor | ||
| * @internal | ||
| */ | ||
| constructor(app: App) { | ||
|
|
||
| this.appInternal = app; | ||
| this.fpnvVerifier = new FirebasePhoneNumberTokenVerifier( | ||
| CLIENT_CERT_URL, | ||
| 'https://fpnv.googleapis.com/projects/', | ||
| PN_TOKEN_INFO, | ||
| app | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the app associated with this `Fpnv` instance. | ||
| * | ||
| * @returns The app associated with this `Fpnv` instance. | ||
| */ | ||
| get app(): App { | ||
boikoa-gl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return this.appInternal; | ||
| } | ||
|
|
||
boikoa-gl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public async verifyToken(fpnvJwt: string): Promise<FpnvToken> { | ||
| return await this.fpnvVerifier.verifyJWT(fpnvJwt); | ||
| } | ||
| } | ||
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 |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /** | ||
| * Firebase Phone Number Verification. | ||
| * | ||
| * @packageDocumentation | ||
| */ | ||
|
|
||
| /*! | ||
| * @license | ||
| * Copyright 2025 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { App, getApp } from '../app'; | ||
| import { FirebaseApp } from '../app/firebase-app'; | ||
| import { Fpnv } from './fpnv'; | ||
|
|
||
| export { | ||
| Fpnv | ||
| } from './fpnv'; | ||
|
|
||
| export { | ||
| FpnvToken, | ||
| } from './fpnv-api' | ||
|
|
||
| /** | ||
| * Gets the {@link Fpnv} service for the default app or a | ||
| * given app. | ||
| * | ||
| * `getFirebasePnv()` can be called with no arguments to access the default app's | ||
| * {@link Fpnv} service or as `getFirebasePnv(app)` to access the | ||
| * {@link Fpnv} service associated with a specific app. | ||
| * | ||
| * @example | ||
| * ```javascript | ||
| * // Get the Fpnv service for the default app | ||
| * const defaultFpnv = getFirebasePnv(); | ||
| * ``` | ||
| * | ||
| * @example | ||
| * ```javascript | ||
| * // Get the Fpnv service for a given app | ||
| * const otherFpnv = getFirebasePnv(otherApp); | ||
| * ``` | ||
boikoa-gl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * | ||
| */ | ||
| export function getFirebasePnv(app?: App): Fpnv { | ||
| if (typeof app === 'undefined') { | ||
| app = getApp(); | ||
| } | ||
|
|
||
| const firebaseApp: FirebaseApp = app as FirebaseApp; | ||
| return firebaseApp.getOrInitService('fpnv', (app) => new Fpnv(app)); | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.