UNPKG

@kuketo/oidc-client-storage

Version:

This is an angular library which provides complete access to cookies in angular universal apps. Kuketo is esperanto for cookies.

117 lines (110 loc) 5.1 kB
import { APP_BASE_HREF } from '@angular/common'; import * as i0 from '@angular/core'; import { InjectionToken, Injectable, Inject, Optional, NgModule } from '@angular/core'; import { AbstractSecurityStorage } from 'angular-auth-oidc-client'; import * as i1 from '@kuketo/core'; const OIDC_COOKIE_SERIALIZER = new InjectionToken('OIDC_COOKIE_SERIALIZER'); const OIDC_COOKIE_CONFIG = new InjectionToken('OIDC_COOKIE_CONFIG'); class OidcClientStorageService extends AbstractSecurityStorage { constructor(cookieService, baseHref, serializer) { super(); this.cookieService = cookieService; this.baseHref = baseHref; this.serializer = serializer; this.serializer || (this.serializer = JSON); } read(key, configId) { const name = this.getPrefix(key, configId); const value = this.cookieService.get(name); return !!value ? this.serializer.parse(value) : undefined; } write(key, value, configId) { this.cookieService.put(this.getPrefix(key, configId), this.serializer.stringify(value), this.getCookieOptions()); } remove(key, configId) { this.cookieService.delete(this.getPrefix(key, configId), this.getCookieOptions()); } clear(configId) { const regex = new RegExp(`^${this.getPrefix('', configId)}`); this.cookieService.deleteByRegex(regex, this.getCookieOptions()); } getPrefix(key, configId) { return `%oidc[${configId !== null && configId !== void 0 ? configId : ''}]%${key}`; } getCookieOptions() { return { path: this.baseHref, }; } } OidcClientStorageService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.1", ngImport: i0, type: OidcClientStorageService, deps: [{ token: i1.CookiesService }, { token: APP_BASE_HREF }, { token: OIDC_COOKIE_SERIALIZER, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); OidcClientStorageService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.1", ngImport: i0, type: OidcClientStorageService }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.1", ngImport: i0, type: OidcClientStorageService, decorators: [{ type: Injectable }], ctorParameters: function () { return [{ type: i1.CookiesService }, { type: undefined, decorators: [{ type: Inject, args: [APP_BASE_HREF] }] }, { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [OIDC_COOKIE_SERIALIZER] }] }]; } }); function configFactory(baseHref, config = {}) { return Object.assign({ ttl: 3600, path: baseHref, name: '%oidc%' }, config); } class OidcClientStorageModule { constructor(parentModule) { if (!parentModule) { throw new Error('KuketoModule is required for this module to work'); } } static withConfig(config) { return { ngModule: OidcClientStorageModule, providers: [ { provide: OIDC_COOKIE_CONFIG, useFactory(baseHref) { return configFactory(baseHref, config); }, deps: [APP_BASE_HREF], }, OidcClientStorageService, ], }; } } OidcClientStorageModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.1", ngImport: i0, type: OidcClientStorageModule, deps: [{ token: i1.KuketoModule, optional: true }], target: i0.ɵɵFactoryTarget.NgModule }); OidcClientStorageModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.1", ngImport: i0, type: OidcClientStorageModule }); OidcClientStorageModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.1", ngImport: i0, type: OidcClientStorageModule, providers: [ { provide: OIDC_COOKIE_CONFIG, useFactory: configFactory, deps: [APP_BASE_HREF], }, OidcClientStorageService, ] }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.1", ngImport: i0, type: OidcClientStorageModule, decorators: [{ type: NgModule, args: [{ providers: [ { provide: OIDC_COOKIE_CONFIG, useFactory: configFactory, deps: [APP_BASE_HREF], }, OidcClientStorageService, ], }] }], ctorParameters: function () { return [{ type: i1.KuketoModule, decorators: [{ type: Optional }] }]; } }); /* * Public API Surface of oidc-client-storage */ /** * Generated bundle index. Do not edit. */ export { OIDC_COOKIE_CONFIG, OIDC_COOKIE_SERIALIZER, OidcClientStorageModule, OidcClientStorageService }; //# sourceMappingURL=kuketo-oidc-client-storage.js.map