-
Notifications
You must be signed in to change notification settings - Fork 267
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
Added ServiceManager to elect leader for token auto renew service #1117
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1117 +/- ##
==========================================
- Coverage 93.51% 93.43% -0.08%
==========================================
Files 154 158 +4
Lines 4147 4251 +104
Branches 906 922 +16
==========================================
+ Hits 3878 3972 +94
- Misses 253 263 +10
Partials 16 16
Continue to review full report at Codecov.
|
0cb18c7
to
4dc6e37
Compare
|
||
private static knownServices = ['autoRenew', 'syncStorage']; | ||
|
||
constructor(tokenManager: TokenManager, options: TokenManagerOptions = {}) { |
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.
ServiceManager could accept an instance of OktaAuth
(like the AuthStateManager does https://github.com/okta/okta-auth-js/blob/master/lib/AuthStateManager.ts#L53). This would still give it access to the tokenManager
and it's config options, but also future-proofs the ServiceManager, in case we need to add a Service in the future that needs different configs
constructor(sdk: OktaAuth) {
this.sdk = sdk;
this.tokenManager = sdk.tokenManager;
...
}
this.services = new Map(); | ||
} | ||
|
||
private startElector() { |
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.
What happens if the elected leader dies? For example the tab is closed. Is a new leader elected?
@@ -89,6 +87,9 @@ export class TokenManager implements TokenManagerInterface { | |||
if (!isLocalhost()) { | |||
options.expireEarlySeconds = DEFAULT_OPTIONS.expireEarlySeconds; | |||
} | |||
if (!options.broadcastChannelName) { |
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.
this config should moved outside of the TokenManager
export class AutoRenewService extends TokenService { | ||
private renewTimeQueue: Array<number>; | ||
|
||
constructor(tokenManager: TokenManager, options: TokenManagerOptions = {}) { |
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.
This service should have it's own Options
type
private storageListener?: (event: StorageEvent) => void; | ||
private onTokenExpiredHandler?: (key: string) => void; | ||
private syncTimeout: unknown; | ||
export abstract class TokenService implements TokenServiceInterface { |
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.
TokenService
abstract class probably isn't necessary for this effort. A simple Interface
with start/stop is probably sufficient
import { TokenManagerOptions } from '../types'; | ||
import { isBrowser } from '../features'; | ||
|
||
export class AutoRenewService extends TokenService { |
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.
Should implement ServiceInterface
@@ -0,0 +1,7 @@ | |||
export interface TokenServiceInterface { |
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.
rename this to ServiceInterface
. Future services may not be Token/TokenManager related
Included in #1124 |
Added broadcast-channel package to solve cross-tab token renewal issues with tab leader election method.
Added
ServiceManager
that is responsible for:broadcast-channel
AutoRenewService
(depending on leadership status) andSyncStorageService
.(
TokenService
is splitted intoAutoRenewService
andSyncStorageService
, based on https://github.com/okta/okta-auth-js/pull/1108/files)Notes:
syncStorage
should be set to true to start auto-renew only on 1 leader tab. Otherwise auto-renew service will run on every tab.tokenManager.start()
does not start token service anymore.serviceManager.start()
is responsible for starting services and is called inoktaAuth.start()
Internal ref: OKTA-456234 (and OKTA-456251)
Resolves #1001
Cross-tab simulation
before:
cross1.mov
after:
cross2.mov