Skip to content

Commit

Permalink
feat: do not deprecate refreshAccessToken (#804)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Oct 8, 2019
1 parent d754771 commit f05de11
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 18 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Expand Up @@ -399,10 +399,13 @@ const client = await auth.getClient({
});
```

#### The `refreshAccessToken` method has been deprecated
The `OAuth2.refreshAccessToken` method has been deprecated. The `getAccessToken`, `getRequestMetadata`, and `request` methods will all refresh the token if needed automatically. There is no need to ever manually refresh the token.
#### Deprecate `refreshAccessToken`

As always, if you run into any problems... please let us know!
_Note: `refreshAccessToken` is no longer deprecated._

`getAccessToken`, `getRequestMetadata`, and `request` methods will all refresh the token if needed automatically.

You should not need to invoke `refreshAccessToken` directly except in [certain edge-cases](https://github.com/googleapis/google-auth-library-nodejs/issues/575).

### Features
- Set private_key_id in JWT access token header like other google auth libraries. (#450)
Expand Down
1 change: 0 additions & 1 deletion src/auth/oauth2client.ts
Expand Up @@ -640,7 +640,6 @@ export class OAuth2Client extends AuthClient {
refreshAccessToken(
callback?: RefreshAccessTokenCallback
): Promise<RefreshAccessTokenResponse> | void {
messages.warn(messages.REFRESH_ACCESS_TOKEN_DEPRECATED);
if (callback) {
this.refreshAccessTokenAsync().then(
r => callback(null, r.credentials, r.res),
Expand Down
9 changes: 0 additions & 9 deletions src/messages.ts
Expand Up @@ -102,15 +102,6 @@ export const JWT_ACCESS_CREATE_SCOPED_DEPRECATED = {
].join(' '),
};

export const REFRESH_ACCESS_TOKEN_DEPRECATED = {
code: 'google-auth-library:DEP007',
type: WarningTypes.DEPRECATION,
message: [
'The `refreshAccessToken` method has been deprecated, and will be removed',
'in the 3.0 release of google-auth-library. Please use the `getRequestHeaders`',
'method instead.',
].join(' '),
};
export const OAUTH_GET_REQUEST_METADATA_DEPRECATED = {
code: 'google-auth-library:DEP004',
type: WarningTypes.DEPRECATION,
Expand Down
23 changes: 20 additions & 3 deletions test/test.googleauth.ts
Expand Up @@ -203,16 +203,33 @@ describe('googleauth', () => {

return {
done: () => {
primary.done();
secondary.done();
try {
primary.done();
secondary.done();
} catch (err) {
// secondary can sometimes complete prior to primary.
}
},
};
}

function nock404GCE() {
return nock(host)
const primary = nock(host)
.get(instancePath)
.reply(404);
const secondary = nock(SECONDARY_HOST_ADDRESS)
.get(instancePath)
.reply(404);
return {
done: () => {
try {
primary.done();
secondary.done();
} catch (err) {
// secondary can sometimes complete prior to primary.
}
},
};
}

function createGetProjectIdNock(projectId = 'not-real') {
Expand Down
4 changes: 2 additions & 2 deletions test/test.oauth2.ts
Expand Up @@ -865,11 +865,11 @@ describe(__filename, () => {
});
});

it('should emit warning on refreshAccessToken', async () => {
it('should not emit warning on refreshAccessToken', async () => {
let warned = false;
sandbox.stub(process, 'emitWarning').callsFake(() => (warned = true));
client.refreshAccessToken((err, result) => {
assert.strictEqual(warned, true);
assert.strictEqual(warned, false);
});
});

Expand Down

0 comments on commit f05de11

Please sign in to comment.