Skip to content

Commit

Permalink
fix: headers were incorrectly set to application/x-www-form-urlencoded
Browse files Browse the repository at this point in the history
This is a long standing bug that prevents us from setting content-type in
gaxios.

Refs: googleapis/google-api-nodejs-client#2003
Refs: googleapis/gaxios#263
  • Loading branch information
bcoe committed Feb 26, 2021
1 parent 68c76c2 commit 95ff1e5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ export class GoogleToken {
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
assertion: signedJWT,
},
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
headers: {'Content-Type': 'application/json'},
responseType: 'json',
});
this.rawToken = r.data;
Expand Down
16 changes: 7 additions & 9 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,16 +610,14 @@ describe('.getToken()', () => {
});

function createGetTokenMock(code = 200, body?: {}) {
return nock(GOOGLE_TOKEN_URLS[0])
return nock(GOOGLE_TOKEN_URLS[0], {
reqheaders: {'Content-Type': 'application/json'},
})
.replyContentLength()
.post(
GOOGLE_TOKEN_URLS[1],
{
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
assertion: /.?/,
},
{reqheaders: {'Content-Type': 'application/x-www-form-urlencoded'}}
)
.post(GOOGLE_TOKEN_URLS[1], {
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
assertion: /.?/,
})
.reply(code, body);
}

Expand Down

0 comments on commit 95ff1e5

Please sign in to comment.