-
Notifications
You must be signed in to change notification settings - Fork 383
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: Add ability to refresh token automatically before expiration. #208
Conversation
This reverts commit 86c4190.
…leapis#202) BREAKING CHANGE: The IAMAuth, Compute, JWT, JWTAccess, OAuth2, and UserRefreshClient types are no longer available as public properties on the GoogleAuth object. They are now exported directly from the top level module.
ts/lib/auth/computeclient.ts
Outdated
constructor() { | ||
super(); | ||
constructor(refreshTokenEarlyMillis?: number) { | ||
super(undefined, undefined, undefined, undefined, refreshTokenEarlyMillis); |
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.
bea663e
to
ea2eda7
Compare
If I run the the travis tests on my fork of the master branch, without modifying anything, the travis tests fail in the same way. How should I address the failing tests? |
ts/lib/auth/computeclient.ts
Outdated
@@ -39,9 +39,11 @@ export class Compute extends OAuth2Client { | |||
* | |||
* Retrieve access token from the metadata server. | |||
* See: https://developers.google.com/compute/docs/authentication | |||
* | |||
* @param {number=} refreshTokeEarlyMillis The token should be refreshed if it will expire within this many milliseconds. |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Biggest feedback - this should be rebased and submitted against the next
branch, and we should make the constructor changes Ali suggested. I'm happy to submit the constructor change as part of a separate PR if that's helpful.
ts/lib/auth/computeclient.ts
Outdated
constructor() { | ||
super(); | ||
constructor(refreshTokenEarlyMillis?: number) { | ||
super(undefined, undefined, undefined, undefined, refreshTokenEarlyMillis); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
ts/lib/auth/googleauth.ts
Outdated
@@ -105,6 +105,11 @@ export class GoogleAuth { | |||
*/ | |||
public static DefaultTransporter = DefaultTransporter; | |||
|
|||
/** | |||
* @param {number=} refreshTokeEarlyMillis The token should be refreshed if it will expire within this many milliseconds. |
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.
ts/lib/auth/googleauth.ts
Outdated
@@ -400,9 +406,12 @@ export class GoogleAuth { | |||
// Set the JSON contents | |||
this.jsonContent = json; | |||
if (json.type === 'authorized_user') { | |||
client = new UserRefreshClient(); | |||
client = new UserRefreshClient( | |||
undefined, undefined, undefined, this.refreshTokenEarlyMillis); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
ts/lib/auth/googleauth.ts
Outdated
/** | ||
* @param {number=} refreshTokeEarlyMillis The token should be refreshed if it will expire within this many milliseconds. | ||
*/ | ||
constructor(private refreshTokenEarlyMillis?: number) {} |
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.
ts/lib/auth/jwtclient.ts
Outdated
@@ -44,12 +44,13 @@ export class JWT extends OAuth2Client { | |||
* @param {string=} key value of key | |||
* @param {(string|array)=} scopes list of requested scopes or a single scope. | |||
* @param {string=} subject impersonated account's email address. | |||
* @param {number=} refreshTokeEarlyMillis The token should be refreshed if it will expire within this many milliseconds. |
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.
ts/lib/auth/oauth2client.ts
Outdated
@@ -52,17 +53,19 @@ export class OAuth2Client extends AuthClient { | |||
* @param {string=} clientSecret The authentication client secret. | |||
* @param {string=} redirectUri The URI to redirect to after completing the auth request. | |||
* @param {Object=} opt_opts optional options for overriding the given parameters. | |||
* @param {number=} refreshTokeEarlyMillis The token should be refreshed if it will expire within this many milliseconds. |
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.
ts/lib/auth/refreshclient.ts
Outdated
@@ -29,10 +29,14 @@ export class UserRefreshClient extends OAuth2Client { | |||
* @param {string} clientId The authentication client ID. | |||
* @param {string} clientSecret The authentication client secret. | |||
* @param {string} refreshToken The authentication refresh token. | |||
* @param {number=} refreshTokeEarlyMillis The token should be refreshed if it will expire within this many milliseconds. |
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.
ts/test/test.oauth2.ts
Outdated
expiry_date: (new Date()).getTime() + 3000 | ||
}; | ||
|
||
oauth2client.request({uri: 'http://example.com'}, () => { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
ea2eda7
to
a8f3510
Compare
Instead of trying to get the tests to pass on the master branch, please take a look at rebasing against the next branch. |
a8f3510
to
4ebe43a
Compare
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
Opened PR #227, which has these changes on top of the next branch. |
This pull request makes it possible to refresh the token when it is not expired but will expire in some period of time.
This can be used to address the issues described in #133, by allowing users to specify that tokens should be refreshed if they will expire soon. This is also necessary to fix googleapis/cloud-profiler-nodejs#94