Skip to content

Commit

Permalink
PR fixes from #1812
Browse files Browse the repository at this point in the history
  • Loading branch information
joehan committed Jul 21, 2022
1 parent 42d5d1f commit 1866661
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/app/credential-internal.ts
Expand Up @@ -21,7 +21,7 @@ import path = require('path');

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

Expand Down Expand Up @@ -437,7 +437,13 @@ function requestAccessToken(client: HttpClient, request: HttpRequestConfig): Pro
*/
function requestIDToken(client: HttpClient, request: HttpRequestConfig): Promise<string> {
return client.send(request).then((resp) => {
return resp.text || '';
if (!resp.text) {
throw new FirebaseAppError(
AppErrorCodes.INVALID_CREDENTIAL,
`Unexpected response while fetching id token: response.text is undefined`,
);
}
return resp.text;
}).catch((err) => {
throw new FirebaseAppError(AppErrorCodes.INVALID_CREDENTIAL, getErrorMessage(err));
});
Expand Down
2 changes: 1 addition & 1 deletion src/functions/functions-api-client-internal.ts
Expand Up @@ -231,7 +231,7 @@ export class FunctionsApiClient {
: await this.getUrl(resources, FIREBASE_FUNCTION_URL_FORMAT);
task.httpRequest.url = functionUrl;
// When run from a deployed extension, we should be using ComputeEngineCredentials
if (extensionId && this.app.options.credential instanceof ComputeEngineCredential) {
if (validator.isNonEmptyString(extensionId) && this.app.options.credential instanceof ComputeEngineCredential) {
const idToken = await this.app.options.credential.getIDToken(functionUrl);
task.httpRequest.headers = { ...task.httpRequest.headers, 'Authorization': `Bearer ${idToken}` };
// Don't send httpRequest.oidcToken if we set Authorization header, or Cloud Tasks will overwrite it.
Expand Down

0 comments on commit 1866661

Please sign in to comment.