-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb4be5a
commit 9e12e20
Showing
11 changed files
with
192 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { OktaAuthOptions, ServiceInterface } from './types'; | ||
import { AutoRenewService, SyncStorageService } from './services'; | ||
import { OktaAuth } from '.'; | ||
|
||
|
||
export class ServiceManager { | ||
private _sdk: OktaAuth; | ||
private _options: OktaAuthOptions; | ||
private _services: ServiceInterface[]; | ||
|
||
constructor (sdk: OktaAuth) { | ||
this._sdk = sdk; | ||
this._services = []; | ||
this._options = { ...sdk.options, tokenManager: sdk.tokenManager.getOptions() }; | ||
} | ||
|
||
get options() { | ||
return {...this.options}; | ||
} | ||
|
||
start() { | ||
if (this._services.length > 0) { | ||
this.stop(); | ||
} | ||
|
||
const tokenManagerOptions = this._options.tokenManager; | ||
|
||
if (tokenManagerOptions?.autoRenew) { | ||
const autoRenewService = new AutoRenewService(this._sdk.tokenManager, {...tokenManagerOptions}); | ||
autoRenewService.start(); | ||
this._services.push(autoRenewService); | ||
} | ||
|
||
if (tokenManagerOptions?.syncStorage) { | ||
const syncStorageService = new SyncStorageService(this._sdk.tokenManager, {...tokenManagerOptions}); | ||
syncStorageService.start(); | ||
this._services.push(syncStorageService); | ||
} | ||
} | ||
|
||
stop() { | ||
this._services.map(s => s.stop()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.