Skip to content

Commit

Permalink
chore: Update App Check to V1 endpoints (#1632)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahirumaramba committed May 3, 2022
1 parent abdfb00 commit f19eb4f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/app-check/app-check-api-client-internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()}`
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/app-check/token-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/app-check/token-verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions test/unit/app-check/app-check-api-client-internal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('AppCheckApiClient', () => {
const TEST_TOKEN_TO_EXCHANGE = 'signed-custom-token';

const TEST_RESPONSE = {
attestationToken: 'token',
token: 'token',
ttl: '3s'
};

Expand Down Expand Up @@ -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 }
});
Expand All @@ -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);
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/unit/app-check/token-generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit f19eb4f

Please sign in to comment.