feat: add authenticator invalidate (SHOP-231)#134
feat: add authenticator invalidate (SHOP-231)#134vsolovei-smartling wants to merge 1 commit intomasterfrom
Conversation
| public synchronized void invalidate() | ||
| { | ||
| this.authentication = null; | ||
| this.expiresAt = -1; | ||
| this.refreshExpiresAt = -1; | ||
| } |
There was a problem hiding this comment.
There was a problem hiding this comment.
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?
| this.refreshExpiresAt = authentication.getRefreshExpiresIn() * 100 + System.currentTimeMillis(); | ||
| this.refreshExpiresAt = authentication.getRefreshExpiresIn() * 1000 + System.currentTimeMillis(); |
There was a problem hiding this comment.
Seems like the real fix is this one?
There was a problem hiding this comment.
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.
|
Will go with handling in the sdk |
|
After some consideration, I'd still like to go ahead with the PR, even if the |
| @@ -116,19 +116,26 @@ boolean isRefreshable() | |||
| return refreshExpiresAt > clock.currentTimeMillis(); | |||
There was a problem hiding this comment.
I would add a gap period to current ms here also.
There was a problem hiding this comment.
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;
|
Concrete Impact Expected: refresh window = 1800 × 1000 = 1,800,000 ms (30 min) What Happens When isRefreshable() Returns False Prematurely Access token expires (or is within 90s of expiry) → isValid() returns false Symptoms |
| { | ||
| 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.
Also I would consider replacing usage of System.currentTimeMillis with usage of the Clock.
And also replace custom Clock interface with standard java.util.Clock instead (since it's package private I don't think this will be a breaking change).
There was a problem hiding this comment.
What are benefits of usage Clock over plain System.currentTimeMillis?
Having invalidation will allow to retry invalid token