Browse Source

refactoring

pull/24050/head
erdemcaygor 12 months ago
parent
commit
43218a8ded
  1. 23
      npm/ng-packs/packages/oauth/src/lib/services/memory-token-storage.service.ts
  2. 2
      npm/ng-packs/packages/oauth/src/lib/utils/storage.factory.ts

23
npm/ng-packs/packages/oauth/src/lib/services/memory-token-storage.service.ts

@ -1,37 +1,40 @@
import { Injectable } from '@angular/core';
import { inject, Injectable } from '@angular/core';
import { OAuthStorage } from 'angular-oauth2-oidc';
import { AbpLocalStorageService } from '@abp/ng.core';
@Injectable({
providedIn: 'root',
})
export class MemoryTokenStorageService implements OAuthStorage {
private keysShouldStoreLocalstorage = ['PKCE_verifier', 'abpOAuthClientId', 'abp_session', 'refresh_token', 'granted_scopes', 'id_token_claims_obj'];
private keysShouldStoreInMemory = ['access_token'];
private data = new Map<string, string>();
private localStorageService = inject(AbpLocalStorageService);
getItem(key: string): string {
console.log('getItem -->>', key);
if (key !== 'access_token') {
return localStorage.getItem(key);
if (this.keysShouldStoreInMemory.includes(key)) {
return this.data.get(key) || null;
}
return this.data.get(key) || null;
return this.localStorageService.getItem(key);
}
removeItem(key: string): void {
if (key !== 'access_token') {
localStorage.removeItem(key);
if (this.keysShouldStoreInMemory.includes(key)) {
this.data.delete(key);
return;
}
this.data.delete(key);
this.localStorageService.removeItem(key);
}
setItem(key: string, data: string): void {
if (key !== 'access_token') {
if (this.keysShouldStoreInMemory.includes(key)) {
console.log('setItem -->', key, data);
localStorage.setItem(key, data);
this.data.set(key, data);
return;
}
console.log('setItem -->', key, data);
this.data.set(key, data);
this.localStorageService.setItem(key, data);
}
clear() {

2
npm/ng-packs/packages/oauth/src/lib/utils/storage.factory.ts

@ -3,7 +3,7 @@ import { isPlatformBrowser } from '@angular/common';
import { ServerTokenStorageService } from '../services/server-token-storage.service';
import { BrowserTokenStorageService, MemoryTokenStorageService } from '../services';
import { OAuthStorage } from 'angular-oauth2-oidc';
import { AbpLocalStorageService, APP_STARTED_WITH_SSR } from '@abp/ng.core';
import { APP_STARTED_WITH_SSR } from '@abp/ng.core';
export class MockStorage implements Storage {
private data = new Map<string, string>();

Loading…
Cancel
Save