Skip to content

Commit

Permalink
Update docs and move already_consume outside
Browse files Browse the repository at this point in the history
  • Loading branch information
lahirumaramba committed Apr 14, 2023
1 parent 7e76c7b commit c51e981
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
4 changes: 0 additions & 4 deletions etc/firebase-admin.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,10 @@ export namespace appCheck {
// Warning: (ae-forgotten-export) The symbol "AppCheckToken" needs to be exported by the entry point default-namespace.d.ts
export type AppCheckToken = AppCheckToken;
// Warning: (ae-forgotten-export) The symbol "AppCheckTokenOptions" needs to be exported by the entry point default-namespace.d.ts
//
// (undocumented)
export type AppCheckTokenOptions = AppCheckTokenOptions;
// Warning: (ae-forgotten-export) The symbol "DecodedAppCheckToken" needs to be exported by the entry point default-namespace.d.ts
export type DecodedAppCheckToken = DecodedAppCheckToken;
// Warning: (ae-forgotten-export) The symbol "VerifyAppCheckTokenOptions" needs to be exported by the entry point default-namespace.d.ts
//
// (undocumented)
export type VerifyAppCheckTokenOptions = VerifyAppCheckTokenOptions;
// Warning: (ae-forgotten-export) The symbol "VerifyAppCheckTokenResponse" needs to be exported by the entry point default-namespace.d.ts
export type VerifyAppCheckTokenResponse = VerifyAppCheckTokenResponse;
Expand Down
2 changes: 1 addition & 1 deletion etc/firebase-admin.app-check.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export interface AppCheckTokenOptions {
export interface DecodedAppCheckToken {
// (undocumented)
[key: string]: any;
already_consumed?: boolean;
app_id: string;
aud: string[];
exp: number;
Expand All @@ -52,6 +51,7 @@ export interface VerifyAppCheckTokenOptions {

// @public
export interface VerifyAppCheckTokenResponse {
alreadyConsumed?: boolean;
appId: string;
token: DecodedAppCheckToken;
}
Expand Down
37 changes: 25 additions & 12 deletions src/app-check/app-check-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,18 @@ export interface AppCheckTokenOptions {
*/
export interface VerifyAppCheckTokenOptions {
/**
* Sets the one-time use tokens feature.
* When set to `true`, checks if this token has already been consumed.
* This feature requires an additional network call to the backend and could be slower when enabled.
* To use the replay protection feature, set this to true to mark the token as consumed.
* Tokens that are found to be already consumed will be marked as such in the response.
*
* Tokens are only considered to be consumed if it is sent to App Check backend by calling the
* {@link AppCheck.verifyToken} method with this field set to `true`; other uses of the token
* do not consume it.
*
* This replay protection feature requires an additional network call to the App Check backend
* and forces your clients to obtain a fresh attestation from your chosen attestation providers.
* This can therefore negatively impact performance and can potentially deplete your attestation
* providers' quotas faster. We recommend that you use this feature only for protecting
* low volume, security critical, or expensive operations.
*/
consume?: boolean;
}
Expand Down Expand Up @@ -98,15 +107,6 @@ export interface DecodedAppCheckToken {
* convenience, and is set as the value of the {@link DecodedAppCheckToken.sub | sub} property.
*/
app_id: string;

/**
* Indicates weather this token was already consumed.
* If this is the first time {@link AppCheck.verifyToken} method has seen this token,
* this field will contain the value `false`. The given token will then be
* marked as `already_consumed` for all future invocations of this {@link AppCheck.verifyToken}
* method for this token.
*/
already_consumed?: boolean;
[key: string]: any;
}

Expand All @@ -123,4 +123,17 @@ export interface VerifyAppCheckTokenResponse {
* The decoded Firebase App Check token.
*/
token: DecodedAppCheckToken;

/**
* Indicates weather this token was already consumed.
* If this is the first time {@link AppCheck.verifyToken} method has seen this token,
* this field will contain the value `false`. The given token will then be
* marked as `already_consumed` for all future invocations of this {@link AppCheck.verifyToken}
* method for this token.
*
* When this field is `true`, the caller is attempting to reuse a previously consumed token.
* You should take precautions against such a caller; for example, you can take actions such as
* rejecting the request or ask the caller to pass additional layers of security checks.
*/
alreadyConsumed?: boolean;
}
6 changes: 6 additions & 0 deletions src/app-check/app-check-namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ export namespace appCheck {
*/
export type VerifyAppCheckTokenResponse = TVerifyAppCheckTokenResponse;

/**
* Type alias to {@link firebase-admin.app-check#AppCheckTokenOptions}.
*/
export type AppCheckTokenOptions = TAppCheckTokenOptions;

/**
* Type alias to {@link firebase-admin.app-check#VerifyAppCheckTokenOptions}.
*/
export type VerifyAppCheckTokenOptions = TVerifyAppCheckTokenOptions;
}
3 changes: 2 additions & 1 deletion src/app-check/app-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ export class AppCheck {
if (options?.consume) {
return this.client.verifyOneTimeProtection(appCheckToken)
.then((alreadyConsumed) => {
decodedToken.already_consumed = alreadyConsumed;
//validate response because alreadyConsumed could be undefined
return {
alreadyConsumed,
appId: decodedToken.app_id,
token: decodedToken,
};
Expand Down

0 comments on commit c51e981

Please sign in to comment.