Skip to content

Commit c51e981

Browse files
committed
Update docs and move already_consume outside
1 parent 7e76c7b commit c51e981

5 files changed

+34
-18
lines changed

etc/firebase-admin.api.md

-4
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,10 @@ export namespace appCheck {
5757
// Warning: (ae-forgotten-export) The symbol "AppCheckToken" needs to be exported by the entry point default-namespace.d.ts
5858
export type AppCheckToken = AppCheckToken;
5959
// Warning: (ae-forgotten-export) The symbol "AppCheckTokenOptions" needs to be exported by the entry point default-namespace.d.ts
60-
//
61-
// (undocumented)
6260
export type AppCheckTokenOptions = AppCheckTokenOptions;
6361
// Warning: (ae-forgotten-export) The symbol "DecodedAppCheckToken" needs to be exported by the entry point default-namespace.d.ts
6462
export type DecodedAppCheckToken = DecodedAppCheckToken;
6563
// Warning: (ae-forgotten-export) The symbol "VerifyAppCheckTokenOptions" needs to be exported by the entry point default-namespace.d.ts
66-
//
67-
// (undocumented)
6864
export type VerifyAppCheckTokenOptions = VerifyAppCheckTokenOptions;
6965
// Warning: (ae-forgotten-export) The symbol "VerifyAppCheckTokenResponse" needs to be exported by the entry point default-namespace.d.ts
7066
export type VerifyAppCheckTokenResponse = VerifyAppCheckTokenResponse;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export interface AppCheckTokenOptions {
3333
export interface DecodedAppCheckToken {
3434
// (undocumented)
3535
[key: string]: any;
36-
already_consumed?: boolean;
3736
app_id: string;
3837
aud: string[];
3938
exp: number;
@@ -52,6 +51,7 @@ export interface VerifyAppCheckTokenOptions {
5251

5352
// @public
5453
export interface VerifyAppCheckTokenResponse {
54+
alreadyConsumed?: boolean;
5555
appId: string;
5656
token: DecodedAppCheckToken;
5757
}

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

+25-12
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,18 @@ export interface AppCheckTokenOptions {
4646
*/
4747
export interface VerifyAppCheckTokenOptions {
4848
/**
49-
* Sets the one-time use tokens feature.
50-
* When set to `true`, checks if this token has already been consumed.
51-
* This feature requires an additional network call to the backend and could be slower when enabled.
49+
* To use the replay protection feature, set this to true to mark the token as consumed.
50+
* Tokens that are found to be already consumed will be marked as such in the response.
51+
*
52+
* Tokens are only considered to be consumed if it is sent to App Check backend by calling the
53+
* {@link AppCheck.verifyToken} method with this field set to `true`; other uses of the token
54+
* do not consume it.
55+
*
56+
* This replay protection feature requires an additional network call to the App Check backend
57+
* and forces your clients to obtain a fresh attestation from your chosen attestation providers.
58+
* This can therefore negatively impact performance and can potentially deplete your attestation
59+
* providers' quotas faster. We recommend that you use this feature only for protecting
60+
* low volume, security critical, or expensive operations.
5261
*/
5362
consume?: boolean;
5463
}
@@ -98,15 +107,6 @@ export interface DecodedAppCheckToken {
98107
* convenience, and is set as the value of the {@link DecodedAppCheckToken.sub | sub} property.
99108
*/
100109
app_id: string;
101-
102-
/**
103-
* Indicates weather this token was already consumed.
104-
* If this is the first time {@link AppCheck.verifyToken} method has seen this token,
105-
* this field will contain the value `false`. The given token will then be
106-
* marked as `already_consumed` for all future invocations of this {@link AppCheck.verifyToken}
107-
* method for this token.
108-
*/
109-
already_consumed?: boolean;
110110
[key: string]: any;
111111
}
112112

@@ -123,4 +123,17 @@ export interface VerifyAppCheckTokenResponse {
123123
* The decoded Firebase App Check token.
124124
*/
125125
token: DecodedAppCheckToken;
126+
127+
/**
128+
* Indicates weather this token was already consumed.
129+
* If this is the first time {@link AppCheck.verifyToken} method has seen this token,
130+
* this field will contain the value `false`. The given token will then be
131+
* marked as `already_consumed` for all future invocations of this {@link AppCheck.verifyToken}
132+
* method for this token.
133+
*
134+
* When this field is `true`, the caller is attempting to reuse a previously consumed token.
135+
* You should take precautions against such a caller; for example, you can take actions such as
136+
* rejecting the request or ask the caller to pass additional layers of security checks.
137+
*/
138+
alreadyConsumed?: boolean;
126139
}

src/app-check/app-check-namespace.ts

+6
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ export namespace appCheck {
7474
*/
7575
export type VerifyAppCheckTokenResponse = TVerifyAppCheckTokenResponse;
7676

77+
/**
78+
* Type alias to {@link firebase-admin.app-check#AppCheckTokenOptions}.
79+
*/
7780
export type AppCheckTokenOptions = TAppCheckTokenOptions;
7881

82+
/**
83+
* Type alias to {@link firebase-admin.app-check#VerifyAppCheckTokenOptions}.
84+
*/
7985
export type VerifyAppCheckTokenOptions = TVerifyAppCheckTokenOptions;
8086
}

src/app-check/app-check.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ export class AppCheck {
9191
if (options?.consume) {
9292
return this.client.verifyOneTimeProtection(appCheckToken)
9393
.then((alreadyConsumed) => {
94-
decodedToken.already_consumed = alreadyConsumed;
94+
//validate response because alreadyConsumed could be undefined
9595
return {
96+
alreadyConsumed,
9697
appId: decodedToken.app_id,
9798
token: decodedToken,
9899
};

0 commit comments

Comments
 (0)