-
Notifications
You must be signed in to change notification settings - Fork 372
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
feat: emit an event when new tokens are obtained #341
Conversation
Codecov Report
@@ Coverage Diff @@
## master #341 +/- ##
==========================================
+ Coverage 94.72% 94.75% +0.02%
==========================================
Files 14 14
Lines 948 953 +5
Branches 195 196 +1
==========================================
+ Hits 898 903 +5
Misses 50 50
Continue to review full report at Codecov.
|
src/auth/oauth2client.ts
Outdated
@@ -551,6 +552,9 @@ export class OAuth2Client extends AuthClient { | |||
((new Date()).getTime() + (res.data.expires_in * 1000)); | |||
delete (tokens as CredentialRequest).expires_in; | |||
} | |||
|
|||
this.emit('tokens', tokens); | |||
|
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
test/test.jwt.ts
Outdated
let raisedEvent = false; | ||
jwt.on('tokens', tokens => { | ||
assert.equal(tokens.access_token, 'initial-access-token'); | ||
raisedEvent = true; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
test/test.oauth2.ts
Outdated
|
||
// ensure the tokens event is raised | ||
client.on('tokens', tokens => { | ||
assert.equal(tokens.access_token, 'abc123'); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Today we really have no way to tell users when their access_token was refreshed. Some people store these on the server across multiple requests, so giving them some way to know when it happens would be nice. Users are asking for this over in google-api-nodejs-client.
Resolves #340.