-
Notifications
You must be signed in to change notification settings - Fork 268
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: TokenManager.renew(key) should renew only requested token #656
Conversation
d875717
to
b8a788d
Compare
lib/TokenManager.ts
Outdated
}) | ||
.then(function(freshTokens) { | ||
// store and emit events for freshTokens | ||
tokenMgmtRef.renewPromise[key] = sdk.token.renew(token) |
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.
sdk.token.renew (oidc/renewToken) only handles renew in the hidden iframe way. This change should still keep the renew with refresh approach.
Codecov Report
@@ Coverage Diff @@
## master #656 +/- ##
==========================================
+ Coverage 92.72% 92.88% +0.15%
==========================================
Files 67 67
Lines 2447 2599 +152
Branches 517 559 +42
==========================================
+ Hits 2269 2414 +145
- Misses 178 185 +7
Continue to review full report at Codecov.
|
lib/oidc/renewToken.ts
Outdated
issuer | ||
}) | ||
|
||
// If we have a refresh token, renew using that, otherwise getWithoutPrompt |
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 think it would make sense to add a helper renew function in TokenManager to make the flows check (it's actually looks like a manager
function).
Also, as we expose the renew functions from the top-level (browser.ts), behavior change in the lower-level functions looks like a breaking change to me (changes the public API authClient.token.renew
, which should use getWithoutPrompt
only).
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.
Moved renew token with refresh token flow to TokenManager
a8c7da5
to
e5a8d01
Compare
@shuowu What do you think on the latest change? |
@@ -50,6 +50,7 @@ import { | |||
revokeToken, | |||
renewToken, | |||
renewTokens, | |||
renewTokensWithRefresh, |
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.
Looks like this method does not exist anymore, remove?
@@ -213,6 +214,7 @@ class OktaAuthBrowser extends OktaAuthBase implements OktaAuth, SignoutAPI { | |||
decode: decodeToken, | |||
revoke: revokeToken.bind(null, this), | |||
renew: renewToken.bind(null, this), | |||
renewTokensWithRefresh: renewTokensWithRefresh.bind(null, this), |
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.
remove?
@@ -16,6 +16,7 @@ export * from './util'; | |||
export { decodeToken } from './decodeToken'; | |||
export { revokeToken } from './revokeToken'; | |||
export { renewToken } from './renewToken'; | |||
export { renewTokensWithRefresh } from './renewTokensWithRefresh'; |
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.
remove?
@@ -148,6 +148,7 @@ export interface TokenAPI extends BaseTokenAPI { | |||
revoke(token: RevocableToken): Promise<object>; | |||
renew(token: Token): Promise<Token>; | |||
renewTokens(): Promise<Tokens>; | |||
renewTokensWithRefresh(refreshTokenObject: RefreshToken): Promise<Tokens>; |
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.
remove?
We don't need to add |
This reverts commit 20a8e11.
5e6f48d
to
e88635e
Compare
CHANGELOG.md
Outdated
@@ -1,5 +1,11 @@ | |||
# Changelog | |||
|
|||
## 4.8.1 |
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.
Let's make the change as 4.9.0 (minor), since it adds new top level API.
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #656 +/- ##
==========================================
- Coverage 92.77% 92.66% -0.11%
==========================================
Files 67 67
Lines 2435 2441 +6
Branches 515 516 +1
==========================================
+ Hits 2259 2262 +3
- Misses 176 179 +3 ☔ View full report in Codecov by Sentry. |
Current implementation of
TokenManager.renew
refreshes access token and id token together if user not specifiedresponseType
inOktaAuth
config (as in #559 -responseType
was used only ingetWithoutPrompt
and not in OktaAuth contructor).okta-auth-js/lib/oidc/renewTokens.ts
Line 41 in 5e9af2f
If user uses multiple access tokens with multiple keys (as in issue #559),
TokenManager.renew
will always use key of first access token in token storage to update any access token with new value:okta-auth-js/lib/TokenManager.ts
Line 338 in 5e9af2f
okta-auth-js/lib/TokenManager.ts
Line 187 in 5e9af2f
This will lead to a problem when expired access token will stay in storage. And on
resetExpireEventTimeoutAll
timer to update will fire againokta-auth-js/lib/TokenManager.ts
Line 139 in 5e9af2f
Internal ref: OKTA-352791
Issue: #559