verifyToken method

Future<VerifyAppCheckTokenResponse> verifyToken(
  1. String appCheckToken, [
  2. VerifyAppCheckTokenOptions? options
])

Verifies a Firebase App Check token (JWT). If the token is valid, the promise is fulfilled with the token's decoded claims; otherwise, the promise is rejected.

@param appCheckToken - The App Check token to verify. @param options - Optional {@link VerifyAppCheckTokenOptions} object when verifying an App Check Token.

@returns A promise fulfilled with the token's decoded claims if the App Check token is valid; otherwise, a rejected promise.

Implementation

Future<VerifyAppCheckTokenResponse> verifyToken(
  String appCheckToken, [
  VerifyAppCheckTokenOptions? options,
]) async {
  final decodedToken =
      await _appCheckTokenVerifier.verifyToken(appCheckToken);

  if (options?.consume ?? false) {
    final alreadyConsumed =
        await _client.verifyReplayProtection(appCheckToken);
    return VerifyAppCheckTokenResponse(
      alreadyConsumed: alreadyConsumed,
      appId: decodedToken.appId,
      token: decodedToken,
    );
  }

  return VerifyAppCheckTokenResponse(
    alreadyConsumed: null,
    appId: decodedToken.appId,
    token: decodedToken,
  );
}