app-check package

The Firebase App Check Web SDK.

Firebase App Check does not work in a Node.js environment usingReCaptchaV3Provider orReCaptchaEnterpriseProvider, but can be used in Node.js if you useCustomProvider and write your own attestation method.

Functions

FunctionDescription
function(app, ...)
initializeAppCheck(app, options)Activate App Check for the given app. Can be called only once per app.
function(appCheckInstance, ...)
getLimitedUseToken(appCheckInstance)Requests a Firebase App Check token. This method should be used only if you need to authorize requests to a non-Firebase backend.Returns limited-use tokens that are intended for use with your non-Firebase backend endpoints that are protected with Replay Protection. This method does not affect the token generation behavior of the #getAppCheckToken() method.
getToken(appCheckInstance, forceRefresh)Get the current App Check token. IfforceRefresh is false, this function first checks for a valid token in memory, then local persistence (IndexedDB). If not found, or ifforceRefresh is true, it makes a request to the App Check endpoint for a fresh token. That request attaches to the most recent in-flight request if one is present.
onTokenChanged(appCheckInstance, observer)Registers a listener to changes in the token state. There can be more than one listener registered at the same time for one or more App Check instances. The listeners call back on the UI thread whenever the current token associated with this App Check instance changes.
onTokenChanged(appCheckInstance, onNext, onError, onCompletion)Registers a listener to changes in the token state. There can be more than one listener registered at the same time for one or more App Check instances. The listeners call back on the UI thread whenever the current token associated with this App Check instance changes.
setTokenAutoRefreshEnabled(appCheckInstance, isTokenAutoRefreshEnabled)Set whether App Check will automatically refresh tokens as needed.

Classes

ClassDescription
CustomProviderCustom provider class.
ReCaptchaEnterpriseProviderApp Check provider that can obtain a reCAPTCHA Enterprise token and exchange it for an App Check token.
ReCaptchaV3ProviderApp Check provider that can obtain a reCAPTCHA V3 token and exchange it for an App Check token.

Interfaces

InterfaceDescription
AppCheckThe Firebase App Check service interface.
AppCheckOptionsOptions for App Check initialization.
AppCheckTokenThe token returned from an App Check provider.
AppCheckTokenResultResult returned bygetToken().
CustomProviderOptionsOptions when creating aCustomProvider.

Type Aliases

Type AliasDescription
AppCheckTokenListenerA listener that is called whenever the App Check token changes.

function(app, ...)

initializeAppCheck(app, options)

Activate App Check for the given app. Can be called only once per app.

Signature:

exportdeclarefunctioninitializeAppCheck(app:FirebaseApp|undefined,options:AppCheckOptions):AppCheck;

Parameters

ParameterTypeDescription
appFirebaseApp | undefinedtheFirebaseApp to activate App Check for
optionsAppCheckOptionsApp Check initialization options

Returns:

AppCheck

function(appCheckInstance, ...)

getLimitedUseToken(appCheckInstance)

Requests a Firebase App Check token. This method should be used only if you need to authorize requests to a non-Firebase backend.

Returns limited-use tokens that are intended for use with your non-Firebase backend endpoints that are protected with Replay Protection. This method does not affect the token generation behavior of the #getAppCheckToken() method.

Signature:

exportdeclarefunctiongetLimitedUseToken(appCheckInstance:AppCheck):Promise<AppCheckTokenResult>;

Parameters

ParameterTypeDescription
appCheckInstanceAppCheckThe App Check service instance.

Returns:

Promise<AppCheckTokenResult>

The limited use token.

getToken(appCheckInstance, forceRefresh)

Get the current App Check token. IfforceRefresh is false, this function first checks for a valid token in memory, then local persistence (IndexedDB). If not found, or ifforceRefresh is true, it makes a request to the App Check endpoint for a fresh token. That request attaches to the most recent in-flight request if one is present.

Signature:

exportdeclarefunctiongetToken(appCheckInstance:AppCheck,forceRefresh?:boolean):Promise<AppCheckTokenResult>;

Parameters

ParameterTypeDescription
appCheckInstanceAppCheckThe App Check service instance.
forceRefreshbooleanIf true, will always try to fetch a fresh token. If false, will use a cached token if found in storage.

Returns:

Promise<AppCheckTokenResult>

onTokenChanged(appCheckInstance, observer)

Registers a listener to changes in the token state. There can be more than one listener registered at the same time for one or more App Check instances. The listeners call back on the UI thread whenever the current token associated with this App Check instance changes.

Signature:

exportdeclarefunctiononTokenChanged(appCheckInstance:AppCheck,observer:PartialObserver<AppCheckTokenResult>):Unsubscribe;

Parameters

ParameterTypeDescription
appCheckInstanceAppCheckThe App Check service instance.
observerPartialObserver<AppCheckTokenResult>An object withnext,error, andcomplete properties.next is called with anAppCheckTokenResult whenever the token changes.error is optional and is called if an error is thrown by the listener (thenext function).complete is unused, as the token stream is unending.

Returns:

Unsubscribe

A function that unsubscribes this listener.

onTokenChanged(appCheckInstance, onNext, onError, onCompletion)

Registers a listener to changes in the token state. There can be more than one listener registered at the same time for one or more App Check instances. The listeners call back on the UI thread whenever the current token associated with this App Check instance changes.

Signature:

exportdeclarefunctiononTokenChanged(appCheckInstance:AppCheck,onNext:(tokenResult:AppCheckTokenResult)=>void,onError?:(error:Error)=>void,onCompletion?:()=>void):Unsubscribe;

Parameters

ParameterTypeDescription
appCheckInstanceAppCheckThe App Check service instance.
onNext(tokenResult:AppCheckTokenResult) => voidWhen the token changes, this function is called with anAppCheckTokenResult.
onError(error: Error) => voidOptional. Called if there is an error thrown by the listener (theonNext function).
onCompletion() => voidCurrently unused, as the token stream is unending.

Returns:

Unsubscribe

A function that unsubscribes this listener.

setTokenAutoRefreshEnabled(appCheckInstance, isTokenAutoRefreshEnabled)

Set whether App Check will automatically refresh tokens as needed.

Signature:

exportdeclarefunctionsetTokenAutoRefreshEnabled(appCheckInstance:AppCheck,isTokenAutoRefreshEnabled:boolean):void;

Parameters

ParameterTypeDescription
appCheckInstanceAppCheckThe App Check service instance.
isTokenAutoRefreshEnabledbooleanIf true, the SDK automatically refreshes App Check tokens as needed. This overrides any value set duringinitializeAppCheck().

Returns:

void

AppCheckTokenListener

A listener that is called whenever the App Check token changes.

Signature:

exporttypeAppCheckTokenListener=(token:AppCheckTokenResult)=>void;

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-11-14 UTC.