Skip to content

Commit 38e5a17

Browse files
committed
chore: resolve commnets
1 parent fabcf80 commit 38e5a17

File tree

5 files changed

+166
-133
lines changed

5 files changed

+166
-133
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*!
2+
* @license
3+
* Copyright 2025 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { PrefixedFirebaseError } from '../utils/error';
19+
20+
export interface FirebasePhoneNumberTokenInfo {
21+
/** Documentation URL. */
22+
url: string;
23+
/** verify API name. */
24+
verifyApiName: string;
25+
/** The JWT full name. */
26+
jwtName: string;
27+
/** The JWT short name. */
28+
shortName: string;
29+
/** The JWT typ" (Type) */
30+
typ: string;
31+
}
32+
33+
export const CLIENT_CERT_URL = 'https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com';
34+
35+
export const PN_TOKEN_INFO: FirebasePhoneNumberTokenInfo = {
36+
url: 'https://firebase.google.com/docs/phone-number-verification',
37+
verifyApiName: 'verifyToken()',
38+
jwtName: 'Firebase Phone Verification token',
39+
shortName: 'FPNV token',
40+
typ: 'JWT',
41+
};
42+
43+
export const FPNV_ERROR_CODE_MAPPING = {
44+
INVALID_ARGUMENT: 'invalid-argument',
45+
INVALID_TOKEN: 'invalid-token',
46+
EXPIRED_TOKEN: 'expired-token',
47+
} satisfies Record<string, FpnvErrorCode>;
48+
49+
export type FpnvErrorCode =
50+
| 'invalid-argument'
51+
| 'invalid-token'
52+
| 'expired-token'
53+
54+
/**
55+
* Firebase Phone Number Verification error code structure. This extends `PrefixedFirebaseError`.
56+
*
57+
* @param code - The error code.
58+
* @param message - The error message.
59+
* @constructor
60+
*/
61+
export class FirebasePnvError extends PrefixedFirebaseError {
62+
constructor(code: FpnvErrorCode, message: string) {
63+
super('fpnv', code, message);
64+
65+
/* tslint:disable:max-line-length */
66+
// Set the prototype explicitly. See the following link for more details:
67+
// https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work
68+
/* tslint:enable:max-line-length */
69+
(this as any).__proto__ = FirebasePnvError.prototype;
70+
}
71+
}

src/fpnv/fpnv-api.ts

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,61 @@
2020
* Interface representing a Fpnv token.
2121
*/
2222
export interface FpnvToken {
23-
aud: string;
24-
auth_time: number;
23+
/**
24+
* The issuer identifier for the issuer of the response.
25+
* This value is a URL with the format
26+
* `https://firebaseappcheck.googleapis.com/<PROJECT_NUMBER>`, where `<PROJECT_NUMBER>` is the
27+
* same project number specified in the {@link aud} property.
28+
*/
29+
iss: string;
30+
31+
/**
32+
* The audience for which this token is intended.
33+
* This value is a JSON array of two strings, the first is the project number of your
34+
* Firebase project, and the second is the project ID of the same project.
35+
*/
36+
aud: string[];
37+
38+
/**
39+
* The Fpnv token's expiration time, in seconds since the Unix epoch. That is, the
40+
* time at which this Fpnv token expires and should no longer be considered valid.
41+
*/
2542
exp: number;
43+
44+
/**
45+
* The Fpnv token's issued-at time, in seconds since the Unix epoch. That is, the
46+
* time at which this Fpnv token was issued and should start to be considered
47+
* valid.
48+
*/
2649
iat: number;
27-
iss: string;
50+
51+
/**
52+
* The phone number of User.
53+
*/
2854
sub: string;
2955

56+
/**
57+
* Unique ID.
58+
*/
59+
jti: string;
60+
61+
/**
62+
* Unique ID.
63+
*/
64+
nonce: string;
65+
66+
/**
67+
* The corresponding user's phone number.
68+
* This value is not actually one of the JWT token claims. It is added as a
69+
* convenience, and is set as the value of the {@link sub} property.
70+
*/
3071
getPhoneNumber(): string;
3172

3273
/**
33-
* Other arbitrary claims included in the ID token.
74+
* Other arbitrary claims included in the token.
3475
*/
3576
[key: string]: any;
3677
}
3778

38-
export { FpnvErrorCode, FirebasePnvError } from '../utils/error';
79+
export { FpnvErrorCode, FirebasePnvError } from './fpnv-api-client-internal';
3980

src/fpnv/fpnv.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,42 @@
1717

1818
import { App } from '../app';
1919
import { FpnvToken } from './fpnv-api';
20-
import {
21-
FirebasePhoneNumberTokenVerifier,
22-
createFPNTVerifier,
23-
} from './token-verifier';
20+
import { FirebasePhoneNumberTokenVerifier } from './token-verifier';
21+
import { CLIENT_CERT_URL, PN_TOKEN_INFO } from './fpnv-api-client-internal';
2422

2523
/**
2624
* Fpnv service bound to the provided app.
2725
*/
28-
export class Fpnv {
29-
private readonly app_: App;
30-
26+
export class Fpnv {
27+
private readonly appInternal: App;
3128
protected readonly fpnvVerifier: FirebasePhoneNumberTokenVerifier;
3229

30+
/**
31+
* @param app - The app for this `Fpnv` service.
32+
* @constructor
33+
* @internal
34+
*/
3335
constructor(app: App) {
3436

35-
this.app_ = app;
36-
this.fpnvVerifier = createFPNTVerifier(app);
37+
this.appInternal = app;
38+
this.fpnvVerifier = new FirebasePhoneNumberTokenVerifier(
39+
CLIENT_CERT_URL,
40+
'https://fpnv.googleapis.com/projects/',
41+
PN_TOKEN_INFO,
42+
app
43+
);
3744
}
3845

3946
/**
40-
* Returns the app associated with this Auth instance.
47+
* Returns the app associated with this `Fpnv` instance.
4148
*
42-
* @returns The app associated with this Auth instance.
49+
* @returns The app associated with this `Fpnv` instance.
4350
*/
4451
get app(): App {
45-
return this.app_;
52+
return this.appInternal;
4653
}
4754

48-
public async verifyToken(idToken: string): Promise<FpnvToken> {
49-
return await this.fpnvVerifier.verifyJWT(idToken);
55+
public async verifyToken(fpnvJwt: string): Promise<FpnvToken> {
56+
return await this.fpnvVerifier.verifyJWT(fpnvJwt);
5057
}
5158
}

0 commit comments

Comments
 (0)