123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.AppCheck = void 0;
- const validator = require("../utils/validator");
- const app_check_api_client_internal_1 = require("./app-check-api-client-internal");
- const token_generator_1 = require("./token-generator");
- const token_verifier_1 = require("./token-verifier");
- const crypto_signer_1 = require("../utils/crypto-signer");
- class AppCheck {
-
- constructor(app) {
- this.app = app;
- this.client = new app_check_api_client_internal_1.AppCheckApiClient(app);
- try {
- this.tokenGenerator = new token_generator_1.AppCheckTokenGenerator((0, crypto_signer_1.cryptoSignerFromApp)(app));
- }
- catch (err) {
- throw (0, token_generator_1.appCheckErrorFromCryptoSignerError)(err);
- }
- this.appCheckTokenVerifier = new token_verifier_1.AppCheckTokenVerifier(app);
- }
-
- createToken(appId, options) {
- return this.tokenGenerator.createCustomToken(appId, options)
- .then((customToken) => {
- return this.client.exchangeToken(customToken, appId);
- });
- }
-
- verifyToken(appCheckToken, options) {
- this.validateVerifyAppCheckTokenOptions(options);
- return this.appCheckTokenVerifier.verifyToken(appCheckToken)
- .then((decodedToken) => {
- if (options?.consume) {
- return this.client.verifyReplayProtection(appCheckToken)
- .then((alreadyConsumed) => {
- return {
- alreadyConsumed,
- appId: decodedToken.app_id,
- token: decodedToken,
- };
- });
- }
- return {
- appId: decodedToken.app_id,
- token: decodedToken,
- };
- });
- }
- validateVerifyAppCheckTokenOptions(options) {
- if (typeof options === 'undefined') {
- return;
- }
- if (!validator.isNonNullObject(options)) {
- throw new app_check_api_client_internal_1.FirebaseAppCheckError('invalid-argument', 'VerifyAppCheckTokenOptions must be a non-null object.');
- }
- }
- }
- exports.AppCheck = AppCheck;
|