Skip to content

Commit

Permalink
fix: use quota_project_id field instead of quota_project (#832)
Browse files Browse the repository at this point in the history
  • Loading branch information
broady authored and bcoe committed Nov 25, 2019
1 parent 2327cc2 commit 8933966
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/auth/credentials.ts
Expand Up @@ -37,7 +37,7 @@ export interface JWTInput {
client_id?: string;
client_secret?: string;
refresh_token?: string;
quota_project?: string;
quota_project_id?: string;
}

export interface CredentialBody {
Expand Down
2 changes: 1 addition & 1 deletion src/auth/jwtclient.ts
Expand Up @@ -265,7 +265,7 @@ export class JWT extends OAuth2Client {
this.key = json.private_key;
this.keyId = json.private_key_id;
this.projectId = json.project_id;
this.quotaProject = json.quota_project;
this.quotaProjectId = json.quota_project_id;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/auth/oauth2client.ts
Expand Up @@ -365,7 +365,7 @@ export class OAuth2Client extends AuthClient {
private certificateCache: Certificates = {};
private certificateExpiry: Date | null = null;
private certificateCacheFormat: CertificateFormat = CertificateFormat.PEM;
protected quotaProject?: string;
protected quotaProjectId?: string;
protected refreshTokenPromises = new Map<string, Promise<GetTokenResponse>>();

// TODO: refactor tests to make this private
Expand Down Expand Up @@ -742,14 +742,14 @@ export class OAuth2Client extends AuthClient {
*/
async getRequestHeaders(url?: string): Promise<Headers> {
const headers = (await this.getRequestMetadataAsync(url)).headers;
// quota_project, stored in application_default_credentials.json, is set in
// quota_project_id, stored in application_default_credentials.json, is set in
// the x-goog-user-project header, to indicate an alternate account for
// billing and quota:
if (
!headers['x-goog-user-project'] && // don't override a value the user sets.
this.quotaProject
this.quotaProjectId
) {
headers['x-goog-user-project'] = this.quotaProject;
headers['x-goog-user-project'] = this.quotaProjectId;
}
return headers;
}
Expand Down
2 changes: 1 addition & 1 deletion src/auth/refreshclient.ts
Expand Up @@ -115,7 +115,7 @@ export class UserRefreshClient extends OAuth2Client {
this._clientSecret = json.client_secret;
this._refreshToken = json.refresh_token;
this.credentials.refresh_token = json.refresh_token;
this.quotaProject = json.quota_project;
this.quotaProjectId = json.quota_project_id;
}

/**
Expand Down
Expand Up @@ -4,5 +4,5 @@
"refresh_token": "refreshtoken",
"type": "authorized_user",
"project_id": "my-project",
"quota_project": "my-quota-project"
"quota_project_id": "my-quota-project"
}
2 changes: 1 addition & 1 deletion test/test.refresh.ts
Expand Up @@ -123,7 +123,7 @@ it('fromStream should read the stream and create a UserRefreshClient', done => {
});
});

it('getRequestHeaders should populate x-goog-user-project header if quota_project present', async () => {
it('getRequestHeaders should populate x-goog-user-project header if quota_project_id present', async () => {
// The first time auth.getRequestHeaders() is called /token endpoint is used to
// fetch a JWT.
const req = nock('https://oauth2.googleapis.com')
Expand Down

0 comments on commit 8933966

Please sign in to comment.