Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: deprecate the refreshAccessToken methods #411

Merged
merged 1 commit into from
Jul 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/auth/oauth2client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import crypto from 'crypto';
import * as http from 'http';
import querystring from 'querystring';
import * as stream from 'stream';

import * as messages from '../messages';
import {PemVerifier} from './../pemverifier';
import {BodyResponseCallback} from './../transporters';
import {AuthClient} from './authclient';
Expand Down Expand Up @@ -561,6 +561,7 @@ export class OAuth2Client extends AuthClient {
refreshAccessToken(callback: RefreshAccessTokenCallback): void;
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), callback);
Expand Down Expand Up @@ -605,7 +606,7 @@ export class OAuth2Client extends AuthClient {
throw new Error('No refresh token is set.');
}

const r = await this.refreshAccessToken();
const r = await this.refreshAccessTokenAsync();
if (!r.credentials || (r.credentials && !r.credentials.access_token)) {
throw new Error('Could not refresh access token.');
}
Expand Down
10 changes: 10 additions & 0 deletions src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,13 @@ export const DEFAULT_PROJECT_ID_DEPRECATED = {
'method instead.'
].join(' ')
};

export const REFRESH_ACCESS_TOKEN_DEPRECATED = {
code: 'google-auth-library:DEP003',
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 `getRequestMetadata`',
'method instead.'
].join(' ')
};
1 change: 0 additions & 1 deletion src/transporters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export interface Transporter {

export interface BodyResponseCallback<T> {
// The `body` object is a truly dynamic type. It must be `any`.
// tslint:disable-next-line no-any
(err: Error|null, res?: AxiosResponse<T>|null): void;
}

Expand Down
14 changes: 13 additions & 1 deletion test/test.oauth2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import * as fs from 'fs';
import nock from 'nock';
import path from 'path';
import qs from 'querystring';
import sinon, {SinonSandbox} from 'sinon';
import url from 'url';

import {CodeChallengeMethod, GoogleAuth, OAuth2Client} from '../src';
import {CodeChallengeMethod, OAuth2Client} from '../src';
import {LoginTicket} from '../src/auth/loginticket';

nock.disableNetConnect();
Expand All @@ -42,12 +43,15 @@ const certsResPath =
path.join(__dirname, '../../test/fixtures/oauthcerts.json');

let client: OAuth2Client;
let sandbox: SinonSandbox;
beforeEach(() => {
client = new OAuth2Client(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
sandbox = sinon.createSandbox();
});

afterEach(() => {
nock.cleanAll();
sandbox.restore();
});

it('should generate a valid consent page url', done => {
Expand Down Expand Up @@ -714,6 +718,14 @@ it('should return error in callback on request', done => {
});
});

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

it('should return error in callback on refreshAccessToken', done => {
client.refreshAccessToken((err, result) => {
assert.equal(err!.message, 'No refresh token is set.');
Expand Down