Skip to content

Commit f65945d

Browse files
committed
chore: Update FAC to beta (#1263)
1 parent 3ab54ad commit f65945d

File tree

6 files changed

+44
-14
lines changed

6 files changed

+44
-14
lines changed

src/app-check/app-check-api-client-internal.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import * as validator from '../utils/validator';
2828
import AppCheckToken = appCheck.AppCheckToken;
2929

3030
// App Check backend constants
31-
const FIREBASE_APP_CHECK_V1_API_URL_FORMAT = 'https://firebaseappcheck.googleapis.com/v1alpha/projects/{projectId}/apps/{appId}:exchangeCustomToken';
31+
const FIREBASE_APP_CHECK_V1_API_URL_FORMAT = 'https://firebaseappcheck.googleapis.com/v1beta/projects/{projectId}/apps/{appId}:exchangeCustomToken';
3232

3333
const FIREBASE_APP_CHECK_CONFIG_HEADERS = {
3434
'X-Firebase-Client': `fire-admin-node/${utils.getSdkVersion()}`
@@ -147,9 +147,9 @@ export class AppCheckApiClient {
147147
*/
148148
private toAppCheckToken(resp: HttpResponse): AppCheckToken {
149149
const token = resp.data.attestationToken;
150-
// `timeToLive` is a string with the suffix "s" preceded by the number of seconds,
150+
// `ttl` is a string with the suffix "s" preceded by the number of seconds,
151151
// with nanoseconds expressed as fractional seconds.
152-
const ttlMillis = this.stringToMilliseconds(resp.data.timeToLive);
152+
const ttlMillis = this.stringToMilliseconds(resp.data.ttl);
153153
return {
154154
token,
155155
ttlMillis
@@ -169,7 +169,7 @@ export class AppCheckApiClient {
169169
private stringToMilliseconds(duration: string): number {
170170
if (!validator.isNonEmptyString(duration) || !duration.endsWith('s')) {
171171
throw new FirebaseAppCheckError(
172-
'invalid-argument', '`timeToLive` must be a valid duration string with the suffix `s`.');
172+
'invalid-argument', '`ttl` must be a valid duration string with the suffix `s`.');
173173
}
174174
const seconds = duration.slice(0, -1);
175175
return Math.floor(Number(seconds) * 1000);

src/app-check/token-generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { HttpError } from '../utils/api-request';
2929
const ONE_HOUR_IN_SECONDS = 60 * 60;
3030

3131
// Audience to use for Firebase App Check Custom tokens
32-
const FIREBASE_APP_CHECK_AUDIENCE = 'https://firebaseappcheck.googleapis.com/google.firebase.appcheck.v1alpha.TokenExchangeService';
32+
const FIREBASE_APP_CHECK_AUDIENCE = 'https://firebaseappcheck.googleapis.com/google.firebase.appcheck.v1beta.TokenExchangeService';
3333

3434
/**
3535
* Class for generating Firebase App Check tokens.

src/app-check/token-verifier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
import DecodedAppCheckToken = appCheck.DecodedAppCheckToken;
2828

2929
const APP_CHECK_ISSUER = 'https://firebaseappcheck.googleapis.com/';
30-
const JWKS_URL = 'https://firebaseappcheck.googleapis.com/v1alpha/jwks';
30+
const JWKS_URL = 'https://firebaseappcheck.googleapis.com/v1beta/jwks';
3131

3232
/**
3333
* Class for verifying Firebase App Check tokens.

test/integration/app-check.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,34 @@ describe('admin.appCheck', () => {
7070
});
7171
});
7272
});
73+
74+
describe('verifyToken', () => {
75+
let validToken: admin.appCheck.AppCheckToken;
76+
77+
before(async () => {
78+
if (!appId) {
79+
return;
80+
}
81+
// obtain a valid app check token
82+
validToken = await admin.appCheck().createToken(appId as string);
83+
});
84+
85+
it('should succeed with a decoded verifed token response', function() {
86+
if (!appId) {
87+
this.skip();
88+
}
89+
return admin.appCheck().verifyToken(validToken.token)
90+
.then((verifedToken) => {
91+
expect(verifedToken).to.have.keys(['token', 'appId']);
92+
expect(verifedToken.token).to.have.keys(['iss', 'sub', 'aud', 'exp', 'iat', 'app_id']);
93+
expect(verifedToken.token.app_id).to.be.a('string').and.equals(appId);
94+
});
95+
});
96+
97+
it('should propagate API errors', () => {
98+
// rejects with invalid-argument when the token is invalid
99+
return admin.appCheck().verifyToken('invalid-token')
100+
.should.eventually.be.rejected.and.have.property('code', 'app-check/invalid-argument');
101+
});
102+
});
73103
});

test/unit/app-check/app-check-api-client-internal.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('AppCheckApiClient', () => {
5757

5858
const TEST_RESPONSE = {
5959
attestationToken: 'token',
60-
timeToLive: '3s'
60+
ttl: '3s'
6161
};
6262

6363
const mockOptions = {
@@ -182,15 +182,15 @@ describe('AppCheckApiClient', () => {
182182

183183
['', 'abc', '3s2', 'sssa', '3.000000001', '3.2', null, NaN, true, [], {}, 100, 1.2, -200, -2.4]
184184
.forEach((invalidDuration) => {
185-
it(`should throw if the returned timeToLive duration is: ${invalidDuration}`, () => {
185+
it(`should throw if the returned ttl duration is: ${invalidDuration}`, () => {
186186
const response = deepCopy(TEST_RESPONSE);
187-
(response as any).timeToLive = invalidDuration;
187+
(response as any).ttl = invalidDuration;
188188
const stub = sinon
189189
.stub(HttpClient.prototype, 'send')
190190
.resolves(utils.responseFrom(response, 200));
191191
stubs.push(stub);
192192
const expected = new FirebaseAppCheckError(
193-
'invalid-argument', '`timeToLive` must be a valid duration string with the suffix `s`.');
193+
'invalid-argument', '`ttl` must be a valid duration string with the suffix `s`.');
194194
return apiClient.exchangeToken(TEST_TOKEN_TO_EXCHANGE, APP_ID)
195195
.should.eventually.be.rejected.and.deep.include(expected);
196196
});
@@ -207,7 +207,7 @@ describe('AppCheckApiClient', () => {
207207
expect(resp.ttlMillis).to.deep.equal(3000);
208208
expect(stub).to.have.been.calledOnce.and.calledWith({
209209
method: 'POST',
210-
url: `https://firebaseappcheck.googleapis.com/v1alpha/projects/test-project/apps/${APP_ID}:exchangeCustomToken`,
210+
url: `https://firebaseappcheck.googleapis.com/v1beta/projects/test-project/apps/${APP_ID}:exchangeCustomToken`,
211211
headers: EXPECTED_HEADERS,
212212
data: { customToken: TEST_TOKEN_TO_EXCHANGE }
213213
});
@@ -219,10 +219,10 @@ describe('AppCheckApiClient', () => {
219219
// 3 seconds with 0 nanoseconds expressed as "3s"
220220
// 3 seconds and 1 nanosecond expressed as "3.000000001s"
221221
// 3 seconds and 1 microsecond expressed as "3.000001s"
222-
it(`should resolve with ttlMillis as ${ttlMillis} when timeToLive
222+
it(`should resolve with ttlMillis as ${ttlMillis} when ttl
223223
from server is: ${ttlString}`, () => {
224224
const response = deepCopy(TEST_RESPONSE);
225-
(response as any).timeToLive = ttlString;
225+
(response as any).ttl = ttlString;
226226
const stub = sinon
227227
.stub(HttpClient.prototype, 'send')
228228
.resolves(utils.responseFrom(response, 200));

test/unit/app-check/token-generator.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const expect = chai.expect;
4444

4545
const ALGORITHM = 'RS256';
4646
const ONE_HOUR_IN_SECONDS = 60 * 60;
47-
const FIREBASE_APP_CHECK_AUDIENCE = 'https://firebaseappcheck.googleapis.com/google.firebase.appcheck.v1alpha.TokenExchangeService';
47+
const FIREBASE_APP_CHECK_AUDIENCE = 'https://firebaseappcheck.googleapis.com/google.firebase.appcheck.v1beta.TokenExchangeService';
4848

4949
/**
5050
* Verifies a token is signed with the private key corresponding to the provided public key.

0 commit comments

Comments
 (0)