Skip to content

Commit f603e65

Browse files
committed
feat: add basic fpnv
1 parent 179dab7 commit f603e65

File tree

10 files changed

+471
-0
lines changed

10 files changed

+471
-0
lines changed

entrypoints.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
"typings": "./lib/auth/index.d.ts",
1717
"dist": "./lib/auth/index.js"
1818
},
19+
"firebase-admin/fpnv": {
20+
"typings": "./lib/fpnv/index.d.ts",
21+
"dist": "./lib/fpnv/index.js"
22+
},
1923
"firebase-admin/database": {
2024
"typings": "./lib/database/index.d.ts",
2125
"dist": "./lib/database/index.js"

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@
7373
"auth": [
7474
"lib/auth"
7575
],
76+
"fpnv": [
77+
"lib/fpnv"
78+
],
7679
"eventarc": [
7780
"lib/eventarc"
7881
],
@@ -134,6 +137,11 @@
134137
"require": "./lib/auth/index.js",
135138
"import": "./lib/esm/auth/index.js"
136139
},
140+
"./fpnv": {
141+
"types": "./lib/fpnv/index.d.ts",
142+
"require": "./lib/fpnv/index.js",
143+
"import": "./lib/esm/fpnv/index.js"
144+
},
137145
"./database": {
138146
"types": "./lib/database/index.d.ts",
139147
"require": "./lib/database/index.js",

src/firebase-namespace-api.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import { appCheck } from './app-check/app-check-namespace';
1818
import { auth } from './auth/auth-namespace';
19+
import { fpnv } from './fpnv/fpnv-namespace';
1920
import { database } from './database/database-namespace';
2021
import { firestore } from './firestore/firestore-namespace';
2122
import { instanceId } from './instance-id/instance-id-namespace';
@@ -43,6 +44,7 @@ export namespace app {
4344
export interface App extends AppCore {
4445
appCheck(): appCheck.AppCheck;
4546
auth(): auth.Auth;
47+
fpnv(): fpnv.Fpnv;
4648
database(url?: string): database.Database;
4749
firestore(): firestore.Firestore;
4850
installations(): installations.Installations;
@@ -81,6 +83,7 @@ export namespace app {
8183
export * from './credential/index';
8284
export { appCheck } from './app-check/app-check-namespace';
8385
export { auth } from './auth/auth-namespace';
86+
export { fpnv } from './fpnv/fpnv-namespace';
8487
export { database } from './database/database-namespace';
8588
export { firestore } from './firestore/firestore-namespace';
8689
export { instanceId } from './instance-id/instance-id-namespace';

src/fpnv/base-fpnv.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { App } from '../app';
2+
3+
import {
4+
FirebasePhoneNumberTokenVerifier,
5+
FpnvToken,
6+
createFPNTVerifier,
7+
} from './token-verifier';
8+
9+
10+
export abstract class BaseFpnv {
11+
protected readonly fPNTVerifier: FirebasePhoneNumberTokenVerifier;
12+
13+
protected constructor(
14+
app: App,
15+
) {
16+
this.fPNTVerifier = createFPNTVerifier(app);
17+
}
18+
19+
20+
public async verifyToken(idToken: string): Promise<FpnvToken> {
21+
return await this.fPNTVerifier.verifyJWT(idToken);
22+
}
23+
}

src/fpnv/fpnv-namespace.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*!
2+
* Copyright 2021 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { App } from '../app';
18+
19+
// Import all public types with aliases, and re-export from the auth namespace.
20+
21+
import { Fpnv as TFpnv } from './fpnv';
22+
23+
import {
24+
BaseFpnv as TBaseFpnv,
25+
} from './base-fpnv';
26+
27+
import {
28+
FpnvToken as TFpnvToken,
29+
} from './token-verifier';
30+
31+
32+
export declare function fpnv(app?: App): fpnv.Fpnv;
33+
34+
/* eslint-disable @typescript-eslint/no-namespace */
35+
export namespace fpnv {
36+
export type BaseFpnv = TBaseFpnv;
37+
export type Fpnv = TFpnv;
38+
export type FpnvToken = TFpnvToken;
39+
}

src/fpnv/fpnv.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*!
2+
* @license
3+
* Copyright 2017 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 { App } from '../app';
19+
import { BaseFpnv } from './base-fpnv';
20+
21+
/**
22+
* Fpnv service bound to the provided app.
23+
*/
24+
export class Fpnv extends BaseFpnv {
25+
private readonly app_: App;
26+
27+
constructor(app: App) {
28+
super(app);
29+
30+
this.app_ = app;
31+
}
32+
33+
/**
34+
* Returns the app associated with this Fpnv instance.
35+
*
36+
* @returns The app associated with this Fpnv instance.
37+
*/
38+
get app(): App {
39+
return this.app_;
40+
}
41+
}

src/fpnv/index.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*!
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/**
18+
* Firebase Phone Number Verification.
19+
*
20+
* @packageDocumentation
21+
*/
22+
23+
import { App, getApp } from '../app';
24+
import { FirebaseApp } from '../app/firebase-app';
25+
import { Fpnv } from './fpnv';
26+
27+
/**
28+
* Gets the {@link Fpnv} service for the default app or a
29+
* given app.
30+
*
31+
* `getFirebasePnv()` can be called with no arguments to access the default app's
32+
* {@link Fpnv} service or as `getFirebasePnv(app)` to access the
33+
* {@link Fpnv} service associated with a specific app.
34+
*
35+
* @example
36+
* ```javascript
37+
* // Get the Fpnv service for the default app
38+
* const defaultFpnv = getFirebasePnv();
39+
* ```
40+
*
41+
* @example
42+
* ```javascript
43+
* // Get the Fpnv service for a given app
44+
* const otherFpnv = getFirebasePnv(otherApp);
45+
* ```
46+
*
47+
*/
48+
export function getFirebasePnv(app?: App): Fpnv {
49+
if (typeof app === 'undefined') {
50+
app = getApp();
51+
}
52+
53+
const firebaseApp: FirebaseApp = app as FirebaseApp;
54+
return firebaseApp.getOrInitService('fpnv', (app) => new Fpnv(app));
55+
}
56+
57+
export {
58+
Fpnv,
59+
} from './fpnv';
60+
61+
export {
62+
BaseFpnv,
63+
} from './base-fpnv';
64+
65+
66+
export {
67+
FpnvToken,
68+
} from './token-verifier';
69+
70+
71+
export {
72+
FirebasePnvError,
73+
FpnvErrorCode,
74+
} from '../utils/error';

0 commit comments

Comments
 (0)