UNPKG

oidc-client-rx

Version:

ReactiveX enhanced OIDC and OAuth2 protocol support for browser-based JavaScript applications

68 lines (67 loc) 2.85 kB
import { Injectable, inject } from "injection-js"; import { injectAbstractType } from "../injection/index.js"; import { LoggerService } from "../logging/logger.service.js"; import { AbstractSecurityStorage } from "./abstract-security-storage.js"; function _ts_decorate(decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc); else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; } class BrowserStorageService { read(key, configuration) { const { configId } = configuration; if (!configId) { this.loggerService.logDebug(configuration, `Wanted to read '${key}' but configId was '${configId}'`); return null; } if (!this.hasStorage()) { this.loggerService.logDebug(configuration, `Wanted to read '${key}' but Storage was undefined`); return null; } const storedConfig = this.abstractSecurityStorage.read(configId); if (!storedConfig) return null; return JSON.parse(storedConfig); } write(value, configuration) { const { configId } = configuration; if (!configId) { this.loggerService.logDebug(configuration, `Wanted to write but configId was '${configId}'`); return false; } if (!this.hasStorage()) { this.loggerService.logDebug(configuration, "Wanted to write but Storage was falsy"); return false; } value = value || null; this.abstractSecurityStorage.write(configId, JSON.stringify(value)); return true; } remove(key, configuration) { if (!this.hasStorage()) { this.loggerService.logDebug(configuration, `Wanted to remove '${key}' but Storage was falsy`); return false; } this.abstractSecurityStorage.remove(key); return true; } clear(configuration) { if (!this.hasStorage()) { this.loggerService.logDebug(configuration, "Wanted to clear storage but Storage was falsy"); return false; } this.abstractSecurityStorage.clear(); return true; } hasStorage() { return "u" > typeof Storage; } constructor(){ this.loggerService = inject(LoggerService); this.abstractSecurityStorage = injectAbstractType(AbstractSecurityStorage); } } BrowserStorageService = _ts_decorate([ Injectable() ], BrowserStorageService); export { BrowserStorageService };