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!: update token endpoints to non-deprecated endpoints #466

Merged
merged 8 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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 esm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
);
};

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';
const GOOGLE_REVOKE_TOKEN_URL = 'https://oauth2.googleapis.com/revoke?token=';

export interface Transporter {
request<T>(opts: GaxiosOptions): GaxiosPromise<T>;
Expand Down Expand Up @@ -64,7 +63,7 @@
}

class ErrorWithCode extends Error {
constructor(message: string, code: string) {

Check warning on line 66 in esm/src/index.ts

View workflow job for this annotation

GitHub Actions / lint

'code' is defined but never used
super(message);
}
}
Expand Down
43 changes: 21 additions & 22 deletions esm/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
const KEYFILENOEMAILJSON = 'esm/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 @@ -144,7 +144,7 @@
gtoken.expiresAt = new Date().getTime() + 1000;
assert.ok(
!gtoken.isTokenExpiring(),
'should not be expired with future date',
'should not be expired with future date'

Check failure on line 147 in esm/test/index.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
);
gtoken.expiresAt = new Date().getTime() - 1000;
assert.ok(gtoken.isTokenExpiring(), 'should be expired with past date');
Expand All @@ -162,12 +162,12 @@
gtoken.expiresAt = new Date().getTime() + 4 * 60 * 1000;
assert.ok(
gtoken.isTokenExpiring(),
'should be expired with near future date',
'should be expired with near future date'

Check failure on line 165 in esm/test/index.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
);
gtoken.expiresAt = new Date().getTime() + 6 * 60 * 1000;
assert.ok(
!gtoken.isTokenExpiring(),
'shouldnt be expired with future date',
'shouldnt be expired with future date'

Check failure on line 170 in esm/test/index.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
);
gtoken.expiresAt = new Date().getTime() - 10000;
assert.ok(gtoken.isTokenExpiring(), 'should be expired with past date');
Expand All @@ -190,7 +190,7 @@
gtoken.rawToken = {
access_token: token,
};
gtoken.revokeToken(err => {
gtoken.revokeToken(() => {
assert.strictEqual(gtoken.accessToken, undefined);
scope.done();
done();
Expand Down Expand Up @@ -258,7 +258,7 @@
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 @@ -268,7 +268,7 @@
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 @@ -280,7 +280,7 @@
if (err) {
assert.strictEqual(
(err as NodeJS.ErrnoException).code,
'MISSING_CREDENTIALS',
'MISSING_CREDENTIALS'

Check failure on line 283 in esm/test/index.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
);
}
});
Expand All @@ -289,7 +289,7 @@

it('should return err if neither key nor keyfile are set', done => {
const gtoken = new GoogleToken();
gtoken.getToken((err, token) => {
gtoken.getToken(err => {
assert.ok(err);
done();
});
Expand All @@ -298,7 +298,7 @@
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 @@ -315,7 +315,7 @@
});
const gtoken = new GoogleToken(opts);
const scope = createGetTokenMock();
const token = await gtoken.getToken();
await gtoken.getToken();
scope.done();
assert.deepStrictEqual(gtoken.key, KEYCONTENTS);
});
Expand All @@ -327,7 +327,7 @@
if (err) {
assert.strictEqual(
(err as NodeJS.ErrnoException).code,
'MISSING_CREDENTIALS',
'MISSING_CREDENTIALS'

Check failure on line 330 in esm/test/index.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
);
}
});
Expand Down Expand Up @@ -389,7 +389,7 @@
scope.done();
done();
},
{forceRefresh: true},
{forceRefresh: true}

Check failure on line 392 in esm/test/index.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
);
});

Expand Down Expand Up @@ -420,7 +420,7 @@
const tokens = await Promise.all([gtoken.getToken(), gtoken.getToken()]);
assert.deepStrictEqual(
tokens.map(t => t.access_token),
[fakeToken, fakeToken],
[fakeToken, fakeToken]

Check failure on line 423 in esm/test/index.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
);
});
it('should make parallel requests if forceRefresh=true (promise)', async () => {
Expand All @@ -439,7 +439,7 @@
]);
assert.deepStrictEqual(
tokens.map(t => t.access_token).sort(),
[fakeTokenA, fakeTokenB].sort(),
[fakeTokenA, fakeTokenB].sort()

Check failure on line 442 in esm/test/index.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
);
});

Expand All @@ -450,7 +450,7 @@
if (err) {
assert.strictEqual(
(err as NodeJS.ErrnoException).code,
'UNKNOWN_CERTIFICATE_TYPE',
'UNKNOWN_CERTIFICATE_TYPE'

Check failure on line 453 in esm/test/index.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
);
}
});
Expand Down Expand Up @@ -522,7 +522,7 @@
});
const fakeToken = 'nodeftw';
const scope = createGetTokenMock(200, {access_token: fakeToken});
gtoken.getToken((err, token) => {
gtoken.getToken(err => {
scope.done();
assert.strictEqual(err, null);
assert.ok(customTransporterWasUsed);
Expand Down Expand Up @@ -588,7 +588,7 @@
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.ok(err instanceof Error);
if (err) assert.strictEqual(err.message, message);
Expand Down Expand Up @@ -619,7 +619,6 @@
try {
await new GoogleToken(TESTDATA_KEYFILEJSON).getCredentials(KEYFILEJSON);
} catch (err) {
console.log(err);
message = (err as Error).message;
}
assert.strictEqual(message, 'use key rather than keyFile.');
Expand All @@ -635,7 +634,7 @@
grant_type: 'urn:ietf:params:oauth:grant-type:jwt-bearer',
assertion: /.?/,
},
{reqheaders: {'Content-Type': 'application/x-www-form-urlencoded'}},
{reqheaders: {'Content-Type': 'application/x-www-form-urlencoded'}}

Check failure on line 637 in esm/test/index.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `,`
)
.reply(code, body);
}
Expand Down