From d0fdf1d6a1cd4877e5d3aebf56b9dce83a496dbd Mon Sep 17 00:00:00 2001 From: Lahiru Maramba Date: Wed, 6 Apr 2022 10:07:38 -0400 Subject: [PATCH] chore: Update App Check to V1 endpoints --- src/app-check/app-check-api-client-internal.ts | 4 ++-- src/app-check/token-generator.ts | 2 +- src/app-check/token-verifier.ts | 2 +- test/unit/app-check/app-check-api-client-internal.spec.ts | 8 ++++---- test/unit/app-check/token-generator.spec.ts | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/app-check/app-check-api-client-internal.ts b/src/app-check/app-check-api-client-internal.ts index e9ba97ab97..aae736cf63 100644 --- a/src/app-check/app-check-api-client-internal.ts +++ b/src/app-check/app-check-api-client-internal.ts @@ -26,7 +26,7 @@ import * as validator from '../utils/validator'; import { AppCheckToken } from './app-check-api' // App Check backend constants -const FIREBASE_APP_CHECK_V1_API_URL_FORMAT = 'https://firebaseappcheck.googleapis.com/v1beta/projects/{projectId}/apps/{appId}:exchangeCustomToken'; +const FIREBASE_APP_CHECK_V1_API_URL_FORMAT = 'https://firebaseappcheck.googleapis.com/v1/projects/{projectId}/apps/{appId}:exchangeCustomToken'; const FIREBASE_APP_CHECK_CONFIG_HEADERS = { 'X-Firebase-Client': `fire-admin-node/${utils.getSdkVersion()}` @@ -144,7 +144,7 @@ export class AppCheckApiClient { * @returns An AppCheckToken instance. */ private toAppCheckToken(resp: HttpResponse): AppCheckToken { - const token = resp.data.attestationToken; + const token = resp.data.token; // `ttl` is a string with the suffix "s" preceded by the number of seconds, // with nanoseconds expressed as fractional seconds. const ttlMillis = this.stringToMilliseconds(resp.data.ttl); diff --git a/src/app-check/token-generator.ts b/src/app-check/token-generator.ts index c2a76c8640..2cfe3ca14c 100644 --- a/src/app-check/token-generator.ts +++ b/src/app-check/token-generator.ts @@ -31,7 +31,7 @@ const ONE_MINUTE_IN_MILLIS = ONE_MINUTE_IN_SECONDS * 1000; const ONE_DAY_IN_MILLIS = 24 * 60 * 60 * 1000; // Audience to use for Firebase App Check Custom tokens -const FIREBASE_APP_CHECK_AUDIENCE = 'https://firebaseappcheck.googleapis.com/google.firebase.appcheck.v1beta.TokenExchangeService'; +const FIREBASE_APP_CHECK_AUDIENCE = 'https://firebaseappcheck.googleapis.com/google.firebase.appcheck.v1.TokenExchangeService'; /** * Class for generating Firebase App Check tokens. diff --git a/src/app-check/token-verifier.ts b/src/app-check/token-verifier.ts index 313d7945d3..6c6503f05d 100644 --- a/src/app-check/token-verifier.ts +++ b/src/app-check/token-verifier.ts @@ -26,7 +26,7 @@ import { DecodedAppCheckToken } from './app-check-api' import { App } from '../app'; const APP_CHECK_ISSUER = 'https://firebaseappcheck.googleapis.com/'; -const JWKS_URL = 'https://firebaseappcheck.googleapis.com/v1beta/jwks'; +const JWKS_URL = 'https://firebaseappcheck.googleapis.com/v1/jwks'; /** * Class for verifying Firebase App Check tokens. diff --git a/test/unit/app-check/app-check-api-client-internal.spec.ts b/test/unit/app-check/app-check-api-client-internal.spec.ts index b846fd1c68..65bc64d69d 100644 --- a/test/unit/app-check/app-check-api-client-internal.spec.ts +++ b/test/unit/app-check/app-check-api-client-internal.spec.ts @@ -56,7 +56,7 @@ describe('AppCheckApiClient', () => { const TEST_TOKEN_TO_EXCHANGE = 'signed-custom-token'; const TEST_RESPONSE = { - attestationToken: 'token', + token: 'token', ttl: '3s' }; @@ -203,11 +203,11 @@ describe('AppCheckApiClient', () => { stubs.push(stub); return apiClient.exchangeToken(TEST_TOKEN_TO_EXCHANGE, APP_ID) .then((resp) => { - expect(resp.token).to.deep.equal(TEST_RESPONSE.attestationToken); + expect(resp.token).to.deep.equal(TEST_RESPONSE.token); expect(resp.ttlMillis).to.deep.equal(3000); expect(stub).to.have.been.calledOnce.and.calledWith({ method: 'POST', - url: `https://firebaseappcheck.googleapis.com/v1beta/projects/test-project/apps/${APP_ID}:exchangeCustomToken`, + url: `https://firebaseappcheck.googleapis.com/v1/projects/test-project/apps/${APP_ID}:exchangeCustomToken`, headers: EXPECTED_HEADERS, data: { customToken: TEST_TOKEN_TO_EXCHANGE } }); @@ -229,7 +229,7 @@ describe('AppCheckApiClient', () => { stubs.push(stub); return apiClient.exchangeToken(TEST_TOKEN_TO_EXCHANGE, APP_ID) .then((resp) => { - expect(resp.token).to.deep.equal(response.attestationToken); + expect(resp.token).to.deep.equal(response.token); expect(resp.ttlMillis).to.deep.equal(ttlMillis); }); }); diff --git a/test/unit/app-check/token-generator.spec.ts b/test/unit/app-check/token-generator.spec.ts index 7fea6b8594..f892c9fa08 100644 --- a/test/unit/app-check/token-generator.spec.ts +++ b/test/unit/app-check/token-generator.spec.ts @@ -44,7 +44,7 @@ const expect = chai.expect; const ALGORITHM = 'RS256'; const FIVE_MIN_IN_SECONDS = 5 * 60; -const FIREBASE_APP_CHECK_AUDIENCE = 'https://firebaseappcheck.googleapis.com/google.firebase.appcheck.v1beta.TokenExchangeService'; +const FIREBASE_APP_CHECK_AUDIENCE = 'https://firebaseappcheck.googleapis.com/google.firebase.appcheck.v1.TokenExchangeService'; /** * Verifies a token is signed with the private key corresponding to the provided public key.