Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Update App Check to V1 endpoints #1632

Merged
merged 2 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/app-check/app-check-api-client-internal.ts
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
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
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
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
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