diff --git a/src/auth/oauth2client.ts b/src/auth/oauth2client.ts index 2b752f2f..2ee1e2bb 100644 --- a/src/auth/oauth2client.ts +++ b/src/auth/oauth2client.ts @@ -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'; @@ -561,6 +561,7 @@ export class OAuth2Client extends AuthClient { refreshAccessToken(callback: RefreshAccessTokenCallback): void; refreshAccessToken(callback?: RefreshAccessTokenCallback): Promise|void { + messages.warn(messages.REFRESH_ACCESS_TOKEN_DEPRECATED); if (callback) { this.refreshAccessTokenAsync().then( r => callback(null, r.credentials, r.res), callback); @@ -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.'); } diff --git a/src/messages.ts b/src/messages.ts index b8827ee8..ed08ce94 100644 --- a/src/messages.ts +++ b/src/messages.ts @@ -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(' ') +}; diff --git a/src/transporters.ts b/src/transporters.ts index df39d7c6..5953972c 100644 --- a/src/transporters.ts +++ b/src/transporters.ts @@ -31,7 +31,6 @@ export interface Transporter { export interface BodyResponseCallback { // The `body` object is a truly dynamic type. It must be `any`. - // tslint:disable-next-line no-any (err: Error|null, res?: AxiosResponse|null): void; } diff --git a/test/test.oauth2.ts b/test/test.oauth2.ts index 8137b575..13fc4c71 100644 --- a/test/test.oauth2.ts +++ b/test/test.oauth2.ts @@ -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(); @@ -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 => { @@ -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.');