Skip to content

Commit 1866661

Browse files
committed
PR fixes from #1812
1 parent 42d5d1f commit 1866661

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/app/credential-internal.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import path = require('path');
2121

2222
import { Agent } from 'http';
2323
import { Credential, GoogleOAuthAccessToken } from './credential';
24-
import { AppErrorCodes, FirebaseAppError } from '../utils/error';
24+
import { AppErrorCodes, FirebaseAppError, FirebaseError } from '../utils/error';
2525
import { HttpClient, HttpRequestConfig, HttpError, HttpResponse } from '../utils/api-request';
2626
import * as util from '../utils/validator';
2727

@@ -437,7 +437,13 @@ function requestAccessToken(client: HttpClient, request: HttpRequestConfig): Pro
437437
*/
438438
function requestIDToken(client: HttpClient, request: HttpRequestConfig): Promise<string> {
439439
return client.send(request).then((resp) => {
440-
return resp.text || '';
440+
if (!resp.text) {
441+
throw new FirebaseAppError(
442+
AppErrorCodes.INVALID_CREDENTIAL,
443+
`Unexpected response while fetching id token: response.text is undefined`,
444+
);
445+
}
446+
return resp.text;
441447
}).catch((err) => {
442448
throw new FirebaseAppError(AppErrorCodes.INVALID_CREDENTIAL, getErrorMessage(err));
443449
});

src/functions/functions-api-client-internal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ export class FunctionsApiClient {
231231
: await this.getUrl(resources, FIREBASE_FUNCTION_URL_FORMAT);
232232
task.httpRequest.url = functionUrl;
233233
// When run from a deployed extension, we should be using ComputeEngineCredentials
234-
if (extensionId && this.app.options.credential instanceof ComputeEngineCredential) {
234+
if (validator.isNonEmptyString(extensionId) && this.app.options.credential instanceof ComputeEngineCredential) {
235235
const idToken = await this.app.options.credential.getIDToken(functionUrl);
236236
task.httpRequest.headers = { ...task.httpRequest.headers, 'Authorization': `Bearer ${idToken}` };
237237
// Don't send httpRequest.oidcToken if we set Authorization header, or Cloud Tasks will overwrite it.

0 commit comments

Comments
 (0)