verifyToken method

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

Verifies a Firebase App Check token (JWT). If the token is valid, the returned Future completes with the token's decoded claims; otherwise, it throws a FirebaseAppCheckException.

appCheckToken - The App Check token to verify. options - Optional VerifyAppCheckTokenOptions when verifying an App Check Token.

Returns a Future that completes with the token's decoded claims if the App Check token is valid; otherwise, throws.

Implementation

Future<VerifyAppCheckTokenResponse> verifyToken(
  String appCheckToken, [
  VerifyAppCheckTokenOptions? options,
]) async {
  if (appCheckToken.isEmpty) {
    throw FirebaseAppCheckException(
      AppCheckErrorCode.invalidArgument,
      '`appCheckToken` must be a non-empty string.',
    );
  }

  final decodedToken = await _appCheckTokenVerifier.verifyToken(
    appCheckToken,
  );

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

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