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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update token endpoints to non-deprecated endpoints #466

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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: 2 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ const readFile = fs.readFile
);
};

const GOOGLE_TOKEN_URL = 'https://www.googleapis.com/oauth2/v4/token';
const GOOGLE_REVOKE_TOKEN_URL =
'https://accounts.google.com/o/oauth2/revoke?token=';
const GOOGLE_TOKEN_URL = 'https://oauth2.googleapis.com/token';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const GOOGLE_REVOKE_TOKEN_URL = 'https://oauth2.googleapis.com/revoke?token=';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


export interface Transporter {
request<T>(opts: GaxiosOptions): GaxiosPromise<T>;
Expand Down
26 changes: 13 additions & 13 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ const KEYFILEJSON = './test/assets/key.json';
const KEYFILENOEMAILJSON = './test/assets/key-no-email.json';
const KEYCONTENTS = fs.readFileSync(KEYFILE, 'utf8');
const KEYJSONCONTENTS = fs.readFileSync(KEYFILEJSON, 'utf8');
const GOOGLE_TOKEN_URLS = ['https://www.googleapis.com', '/oauth2/v4/token'];
const GOOGLE_TOKEN_URLS = ['https://oauth2.googleapis.com', '/token'];
const GOOGLE_REVOKE_TOKEN_URLS = [
'https://accounts.google.com',
'/o/oauth2/revoke',
'https://oauth2.googleapis.com',
'/revoke',
'?token=',
];

Expand Down Expand Up @@ -180,7 +180,7 @@ describe('.revokeToken()', () => {
gtoken.rawToken = {
access_token: token,
};
gtoken.revokeToken(err => {
gtoken.revokeToken(() => {
assert.strictEqual(gtoken.accessToken, undefined);
scope.done();
done();
Expand Down Expand Up @@ -248,7 +248,7 @@ describe('.getToken()', () => {
it('should read .pem keyFile from file', done => {
const gtoken = new GoogleToken(TESTDATA_KEYFILE);
const scope = createGetTokenMock();
gtoken.getToken((err, token) => {
gtoken.getToken(() => {
assert.deepStrictEqual(gtoken.key, KEYCONTENTS);
scope.done();
done();
Expand All @@ -258,7 +258,7 @@ describe('.getToken()', () => {
it('should read .pem keyFile from file async', async () => {
const gtoken = new GoogleToken(TESTDATA_KEYFILE);
const scope = createGetTokenMock();
const token = await gtoken.getToken();
await gtoken.getToken();
scope.done();
assert.deepStrictEqual(gtoken.key, KEYCONTENTS);
});
Expand All @@ -279,7 +279,7 @@ describe('.getToken()', () => {

it('should return err if neither key nor keyfile are set', done => {
const gtoken = new GoogleToken();
gtoken.getToken((err, token) => {
gtoken.getToken(err => {
assert(err);
done();
});
Expand All @@ -288,7 +288,7 @@ describe('.getToken()', () => {
it('should read .json key from file', done => {
const gtoken = new GoogleToken(TESTDATA_KEYFILEJSON);
const scope = createGetTokenMock();
gtoken.getToken((err, token) => {
gtoken.getToken(err => {
scope.done();
assert.strictEqual(err, null);
const parsed = JSON.parse(KEYJSONCONTENTS);
Expand All @@ -305,7 +305,7 @@ describe('.getToken()', () => {
});
const gtoken = new GoogleToken(opts);
const scope = createGetTokenMock();
const token = await gtoken.getToken();
await gtoken.getToken();
scope.done();
assert.deepStrictEqual(gtoken.key, KEYCONTENTS);
});
Expand Down Expand Up @@ -492,7 +492,7 @@ describe('.getToken()', () => {
});
const fakeToken = 'nodeftw';
const scope = createGetTokenMock(200, {access_token: fakeToken});
gtoken.getToken((err, token) => {
gtoken.getToken(err => {
scope.done();
assert.strictEqual(err, null);
assert(customTransporterWasUsed);
Expand Down Expand Up @@ -527,7 +527,7 @@ describe('.getToken()', () => {
const ERROR = 'An error occurred.';
const gtoken = new GoogleToken(TESTDATA);
const scope = createGetTokenMock(500, {error: ERROR});
gtoken.getToken((err, token) => {
gtoken.getToken(err => {
scope.done();
assert(err);
assert.strictEqual(gtoken.rawToken, undefined);
Expand All @@ -544,7 +544,7 @@ describe('.getToken()', () => {
const DESCRIPTION = 'more detailed message';
const RESPBODY = {error: ERROR, error_description: DESCRIPTION};
const scope = createGetTokenMock(500, RESPBODY);
gtoken.getToken((err, token) => {
gtoken.getToken(err => {
scope.done();
assert(err instanceof Error);
if (err) {
Expand All @@ -558,7 +558,7 @@ describe('.getToken()', () => {
const gtoken = new GoogleToken(TESTDATA);
const message = 'Request failed with status code 404';
const scope = createGetTokenMock(404);
gtoken.getToken((err, token) => {
gtoken.getToken(err => {
scope.done();
assert(err instanceof Error);
if (err) assert.strictEqual(err.message, message);
Expand Down