Skip to content

Commit 3c6a7e3

Browse files
authored
Change https callables to use apps.admin.auth instead of firebase.auth. (#206)
* Change https callables to use apps.admin.auth instead of firebase.auth. * explicitly mock the credential in the admin app * Use the projectId from admin app instead of a constant
1 parent b6c395f commit 3c6a7e3

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

spec/providers/https.spec.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ import * as jwt from 'jsonwebtoken';
2727
import * as mocks from '../fixtures/credential/key.json';
2828
import * as nock from 'nock';
2929
import * as _ from 'lodash';
30-
import { config } from '../../src/index';
30+
import { apps } from '../../src/apps';
3131
import { expect } from 'chai';
32-
import { fakeConfig } from '../support/helpers';
3332

3433
describe('CloudHttpsBuilder', () => {
3534
describe('#onRequest', () => {
@@ -202,13 +201,28 @@ export function generateIdToken(projectId: string): string {
202201
}
203202

204203
describe('callable.FunctionBuilder', () => {
204+
let oldCredential: firebase.credential.Credential = undefined;
205+
205206
before(() => {
206-
config.singleton = fakeConfig();
207-
firebase.initializeApp(config.singleton.firebase);
207+
let credential = {
208+
getAccessToken: () => {
209+
return Promise.resolve({
210+
expires_in: 1000,
211+
access_token: 'fake',
212+
});
213+
},
214+
getCertificate: () => {
215+
return {
216+
projectId: 'aProjectId',
217+
};
218+
},
219+
};
220+
oldCredential = apps().admin.options.credential;
221+
apps().admin.options.credential = credential;
208222
});
209223

210224
after(() => {
211-
delete config.singleton;
225+
apps().admin.options.credential = oldCredential;
212226
});
213227

214228
describe('#onCall', () => {
@@ -361,7 +375,7 @@ describe('callable.FunctionBuilder', () => {
361375

362376
it('should handle auth', async () => {
363377
const mock = mockFetchPublicKeys();
364-
const projectId = config.singleton.firebase['projectId'];
378+
const projectId = apps().admin.options.projectId;
365379
const idToken = generateIdToken(projectId);
366380
await runTest({
367381
httpRequest: request(null, 'application/json', {

src/providers/https.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import { HttpsFunction } from '../cloud-functions';
2424
import * as express from 'express';
2525
import * as firebase from 'firebase-admin';
26+
import { apps } from '../apps';
2627
import * as _ from 'lodash';
2728
import * as cors from 'cors';
2829

@@ -382,7 +383,7 @@ export function onCall(
382383
}
383384
const idToken = match[1];
384385
try {
385-
const authToken = await firebase.auth().verifyIdToken(idToken);
386+
const authToken = await apps().admin.auth().verifyIdToken(idToken);
386387
context.auth = {
387388
uid: authToken.uid,
388389
token: authToken,

0 commit comments

Comments
 (0)