oidc-client-rx
Version:
ReactiveX enhanced OIDC and OAuth2 protocol support for browser-based JavaScript applications
59 lines (58 loc) • 2.37 kB
JavaScript
import { inject } from "@outposts/injection-js";
import { BrowserStorageService } from "./browser-storage.service.js";
class StoragePersistenceService {
read(key, config) {
const storedConfig = this.browserStorageService.read(key, config) || {};
return storedConfig[key];
}
write(key, value, config) {
const storedConfig = this.browserStorageService.read(key, config) || {};
storedConfig[key] = value;
return this.browserStorageService.write(storedConfig, config);
}
remove(key, config) {
const storedConfig = this.browserStorageService.read(key, config) || {};
delete storedConfig[key];
this.browserStorageService.write(storedConfig, config);
}
clear(config) {
this.browserStorageService.clear(config);
}
resetStorageFlowData(config) {
this.remove('session_state', config);
this.remove('storageSilentRenewRunning', config);
this.remove('storageCodeFlowInProgress', config);
this.remove('codeVerifier', config);
this.remove('userData', config);
this.remove('storageCustomParamsAuthRequest', config);
this.remove('access_token_expires_at', config);
this.remove('storageCustomParamsRefresh', config);
this.remove('storageCustomParamsEndSession', config);
this.remove('reusable_refresh_token', config);
}
resetAuthStateInStorage(config) {
this.remove('authzData', config);
this.remove('reusable_refresh_token', config);
this.remove('authnResult', config);
}
getAccessToken(config) {
return this.read('authzData', config);
}
getIdToken(config) {
var _this_read;
return null == (_this_read = this.read('authnResult', config)) ? void 0 : _this_read.id_token;
}
getRefreshToken(config) {
var _this_read;
const refreshToken = null == (_this_read = this.read('authnResult', config)) ? void 0 : _this_read.refresh_token;
if (!refreshToken && config.allowUnsafeReuseRefreshToken) return this.read('reusable_refresh_token', config);
return refreshToken;
}
getAuthenticationResult(config) {
return this.read('authnResult', config);
}
constructor(){
this.browserStorageService = inject(BrowserStorageService);
}
}
export { StoragePersistenceService };