Skip to content
Snippets Groups Projects
dlcm.storage.ts 744 B
Newer Older
Florent Poittevin's avatar
Florent Poittevin committed
import {OAuthStorage} from 'angular-oauth2-oidc';
import {Injectable} from '@angular/core';

/**
 * Custom storage in memory for sensible data like token
 * (cf best practice https://auth0.com/docs/security/store-tokens)
 */
@Injectable()
export class DlcmStorage extends OAuthStorage {
  private storageValues: Map<string, string>;

  constructor() {
    super();
    this.storageValues = new Map<string, string>();
  }

  getItem(key: string): string | null {
Florent Poittevin's avatar
Florent Poittevin committed
    console.log('retrieve ' + key);
Florent Poittevin's avatar
Florent Poittevin committed
    return this.storageValues[key];
  }

  removeItem(key: string): void {
    this.storageValues.delete(key);
  }

  setItem(key: string, data: string): void {
Florent Poittevin's avatar
Florent Poittevin committed
    console.log('store ' + key, data);
Florent Poittevin's avatar
Florent Poittevin committed
    this.storageValues.set(key, data);
  }

}