-
Notifications
You must be signed in to change notification settings - Fork 8
feat: add authenticator invalidate (SHOP-231) #134
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -116,19 +116,26 @@ boolean isRefreshable() | |
| return refreshExpiresAt > clock.currentTimeMillis(); | ||
| } | ||
|
|
||
| public synchronized void invalidate() | ||
| { | ||
| this.authentication = null; | ||
| this.expiresAt = -1; | ||
| this.refreshExpiresAt = -1; | ||
| } | ||
|
Comment on lines
+119
to
+124
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not called by anyone, isn't?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that filter is only for logging. your http client from sdk already gets 401 response isn't? why can't you handle this 401 in sdk directly? |
||
|
|
||
| private synchronized String getAccessTokenInternal() | ||
| { | ||
| this.authentication = api.authenticate(new AuthenticationRequest(userIdentifier, userSecret)); | ||
| this.expiresAt = authentication.getExpiresIn() * 1000 + System.currentTimeMillis(); | ||
| this.refreshExpiresAt = authentication.getRefreshExpiresIn() * 100 + System.currentTimeMillis(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also I would consider replacing usage of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are benefits of usage |
||
| this.refreshExpiresAt = authentication.getRefreshExpiresIn() * 1000 + System.currentTimeMillis(); | ||
|
Comment on lines
-123
to
+130
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like the real fix is this one?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is THE fix, it will reduce full re-authentication count, the only downside of having 100 vs 1000 is the frequency of full re-authentications vs refreshes. |
||
| return authentication.getAccessToken(); | ||
| } | ||
|
|
||
| private synchronized String refreshAccessToken() | ||
| { | ||
| this.authentication = api.refresh(new AuthenticationRefreshRequest(authentication.getRefreshToken())); | ||
| this.expiresAt = authentication.getExpiresIn() * 1000 + System.currentTimeMillis(); | ||
| this.refreshExpiresAt = authentication.getRefreshExpiresIn() * 100 + System.currentTimeMillis(); | ||
| this.refreshExpiresAt = authentication.getRefreshExpiresIn() * 1000 + System.currentTimeMillis(); | ||
| return authentication.getAccessToken(); | ||
| } | ||
| } | ||
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.
I would add a gap period to current ms here also.
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.
Since we are fixing the timeunit conversion, we need to have a time gap here the same as for the
expiresAt. So it should be smth like:refreshExpiresAt > clock.currentTimeMillis() + REFRESH_BEFORE_EXPIRES_MS;