Skip to content

Commit 99b0515

Browse files
committed
feat(fac): Expose FAC APIs from firebase-admin/app-check entry point
1 parent 244a9af commit 99b0515

20 files changed

+330
-205
lines changed

entrypoints.json

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
"typings": "./lib/app/index.d.ts",
99
"dist": "./lib/app/index.js"
1010
},
11+
"firebase-admin/app-check": {
12+
"typings": "./lib/app-check/index.d.ts",
13+
"dist": "./lib/app-check/index.js"
14+
},
1115
"firebase-admin/auth": {
1216
"typings": "./lib/auth/index.d.ts",
1317
"dist": "./lib/auth/index.js"

etc/firebase-admin.api.md

+9-25
Original file line numberDiff line numberDiff line change
@@ -44,34 +44,18 @@ export namespace app {
4444
}
4545

4646
// @public
47-
export function appCheck(app?: app.App): appCheck.AppCheck;
47+
export function appCheck(app?: App): appCheck.AppCheck;
4848

4949
// @public (undocumented)
5050
export namespace appCheck {
51-
export interface AppCheck {
52-
// (undocumented)
53-
app: app.App;
54-
createToken(appId: string): Promise<AppCheckToken>;
55-
verifyToken(appCheckToken: string): Promise<VerifyAppCheckTokenResponse>;
56-
}
57-
export interface AppCheckToken {
58-
token: string;
59-
ttlMillis: number;
60-
}
61-
export interface DecodedAppCheckToken {
62-
// (undocumented)
63-
[key: string]: any;
64-
app_id: string;
65-
aud: string[];
66-
exp: number;
67-
iat: number;
68-
iss: string;
69-
sub: string;
70-
}
71-
export interface VerifyAppCheckTokenResponse {
72-
appId: string;
73-
token: appCheck.DecodedAppCheckToken;
74-
}
51+
// Warning: (ae-forgotten-export) The symbol "AppCheck" needs to be exported by the entry point default-namespace.d.ts
52+
export type AppCheck = AppCheck;
53+
// Warning: (ae-forgotten-export) The symbol "AppCheckToken" needs to be exported by the entry point default-namespace.d.ts
54+
export type AppCheckToken = AppCheckToken;
55+
// Warning: (ae-forgotten-export) The symbol "DecodedAppCheckToken" needs to be exported by the entry point default-namespace.d.ts
56+
export type DecodedAppCheckToken = DecodedAppCheckToken;
57+
// Warning: (ae-forgotten-export) The symbol "VerifyAppCheckTokenResponse" needs to be exported by the entry point default-namespace.d.ts
58+
export type VerifyAppCheckTokenResponse = VerifyAppCheckTokenResponse;
7559
}
7660

7761
// @public

etc/firebase-admin.app-check.api.md

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
## API Report File for "firebase-admin.app-check"
2+
3+
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4+
5+
```ts
6+
7+
import { Agent } from 'http';
8+
9+
// @public
10+
export class AppCheck {
11+
// Warning: (ae-forgotten-export) The symbol "App" needs to be exported by the entry point index.d.ts
12+
//
13+
// (undocumented)
14+
readonly app: App;
15+
createToken(appId: string): Promise<AppCheckToken>;
16+
verifyToken(appCheckToken: string): Promise<VerifyAppCheckTokenResponse>;
17+
}
18+
19+
// @public
20+
export interface AppCheckToken {
21+
token: string;
22+
ttlMillis: number;
23+
}
24+
25+
// @public
26+
export interface DecodedAppCheckToken {
27+
// (undocumented)
28+
[key: string]: any;
29+
app_id: string;
30+
aud: string[];
31+
exp: number;
32+
iat: number;
33+
iss: string;
34+
sub: string;
35+
}
36+
37+
// @public
38+
export function getAppCheck(app?: App): AppCheck;
39+
40+
// @public
41+
export interface VerifyAppCheckTokenResponse {
42+
appId: string;
43+
token: DecodedAppCheckToken;
44+
}
45+
46+
47+
// (No @packageDocumentation comment for this package)
48+
49+
```

package-lock.json

+15-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+7
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
"app": [
6666
"lib/app"
6767
],
68+
"app-check": [
69+
"lib/app-check"
70+
],
6871
"auth": [
6972
"lib/auth"
7073
],
@@ -103,6 +106,10 @@
103106
"require": "./lib/app/index.js",
104107
"import": "./lib/esm/app/index.js"
105108
},
109+
"./app-check": {
110+
"require": "./lib/app-check/index.js",
111+
"import": "./lib/esm/app-check/index.js"
112+
},
106113
"./auth": {
107114
"require": "./lib/auth/index.js",
108115
"import": "./lib/esm/auth/index.js"

src/app-check/app-check-api-client-internal.ts

+10-12
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,15 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { appCheck } from './index';
18+
import { App } from '../app';
19+
import { FirebaseApp } from '../app/firebase-app';
1920
import {
2021
HttpRequestConfig, HttpClient, HttpError, AuthorizedHttpClient, HttpResponse
2122
} from '../utils/api-request';
22-
import { FirebaseApp } from '../app/firebase-app';
2323
import { PrefixedFirebaseError } from '../utils/error';
24-
2524
import * as utils from '../utils/index';
2625
import * as validator from '../utils/validator';
27-
28-
import AppCheckToken = appCheck.AppCheckToken;
26+
import { AppCheckToken } from './app-check-api'
2927

3028
// App Check backend constants
3129
const FIREBASE_APP_CHECK_V1_API_URL_FORMAT = 'https://firebaseappcheck.googleapis.com/v1beta/projects/{projectId}/apps/{appId}:exchangeCustomToken';
@@ -43,21 +41,21 @@ export class AppCheckApiClient {
4341
private readonly httpClient: HttpClient;
4442
private projectId?: string;
4543

46-
constructor(private readonly app: FirebaseApp) {
44+
constructor(private readonly app: App) {
4745
if (!validator.isNonNullObject(app) || !('options' in app)) {
4846
throw new FirebaseAppCheckError(
4947
'invalid-argument',
5048
'First argument passed to admin.appCheck() must be a valid Firebase app instance.');
5149
}
52-
this.httpClient = new AuthorizedHttpClient(app);
50+
this.httpClient = new AuthorizedHttpClient(app as FirebaseApp);
5351
}
5452

5553
/**
5654
* Exchange a signed custom token to App Check token
5755
*
5856
* @param customToken The custom token to be exchanged.
5957
* @param appId The mobile App ID.
60-
* @return A promise that fulfills with a `AppCheckToken`.
58+
* @returns A promise that fulfills with a `AppCheckToken`.
6159
*/
6260
public exchangeToken(customToken: string, appId: string): Promise<AppCheckToken> {
6361
if (!validator.isNonEmptyString(appId)) {
@@ -143,7 +141,7 @@ export class AppCheckApiClient {
143141
* Creates an AppCheckToken from the API response.
144142
*
145143
* @param resp API response object.
146-
* @return An AppCheckToken instance.
144+
* @returns An AppCheckToken instance.
147145
*/
148146
private toAppCheckToken(resp: HttpResponse): AppCheckToken {
149147
const token = resp.data.attestationToken;
@@ -164,7 +162,7 @@ export class AppCheckApiClient {
164162
* is expressed as "3s", while 3 seconds and 1 nanosecond is expressed as "3.000000001s",
165163
* and 3 seconds and 1 microsecond is expressed as "3.000001s".
166164
*
167-
* @return The duration in milliseconds.
165+
* @returns The duration in milliseconds.
168166
*/
169167
private stringToMilliseconds(duration: string): number {
170168
if (!validator.isNonEmptyString(duration) || !duration.endsWith('s')) {
@@ -211,8 +209,8 @@ export type AppCheckErrorCode =
211209
/**
212210
* Firebase App Check error code structure. This extends PrefixedFirebaseError.
213211
*
214-
* @param {AppCheckErrorCode} code The error code.
215-
* @param {string} message The error message.
212+
* @param code The error code.
213+
* @param message The error message.
216214
* @constructor
217215
*/
218216
export class FirebaseAppCheckError extends PrefixedFirebaseError {

src/app-check/app-check-api.ts

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*!
2+
* @license
3+
* Copyright 2021 Google Inc.
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+
/**
19+
* Interface representing an App Check token.
20+
*/
21+
export interface AppCheckToken {
22+
/**
23+
* The Firebase App Check token.
24+
*/
25+
token: string;
26+
27+
/**
28+
* The time-to-live duration of the token in milliseconds.
29+
*/
30+
ttlMillis: number;
31+
}
32+
33+
/**
34+
* Interface representing a decoded Firebase App Check token, returned from the
35+
* {@link appCheck.AppCheck.verifyToken `verifyToken()`} method.
36+
*/
37+
export interface DecodedAppCheckToken {
38+
/**
39+
* The issuer identifier for the issuer of the response.
40+
*
41+
* This value is a URL with the format
42+
* `https://firebaseappcheck.googleapis.com/<PROJECT_NUMBER>`, where `<PROJECT_NUMBER>` is the
43+
* same project number specified in the [`aud`](#aud) property.
44+
*/
45+
iss: string;
46+
47+
/**
48+
* The Firebase App ID corresponding to the app the token belonged to.
49+
*
50+
* As a convenience, this value is copied over to the [`app_id`](#app_id) property.
51+
*/
52+
sub: string;
53+
54+
/**
55+
* The audience for which this token is intended.
56+
*
57+
* This value is a JSON array of two strings, the first is the project number of your
58+
* Firebase project, and the second is the project ID of the same project.
59+
*/
60+
aud: string[];
61+
62+
/**
63+
* The App Check token's expiration time, in seconds since the Unix epoch. That is, the
64+
* time at which this App Check token expires and should no longer be considered valid.
65+
*/
66+
exp: number;
67+
68+
/**
69+
* The App Check token's issued-at time, in seconds since the Unix epoch. That is, the
70+
* time at which this App Check token was issued and should start to be considered
71+
* valid.
72+
*/
73+
iat: number;
74+
75+
/**
76+
* The App ID corresponding to the App the App Check token belonged to.
77+
*
78+
* This value is not actually one of the JWT token claims. It is added as a
79+
* convenience, and is set as the value of the [`sub`](#sub) property.
80+
*/
81+
app_id: string;
82+
[key: string]: any;
83+
}
84+
85+
/**
86+
* Interface representing a verified App Check token response.
87+
*/
88+
export interface VerifyAppCheckTokenResponse {
89+
/**
90+
* The App ID corresponding to the App the App Check token belonged to.
91+
*/
92+
appId: string;
93+
94+
/**
95+
* The decoded Firebase App Check token.
96+
*/
97+
token: DecodedAppCheckToken;
98+
}

0 commit comments

Comments
 (0)