Browse Source

refactoring

pull/24050/head
erdemcaygor 12 months ago
parent
commit
69f21efaf0
  1. 24
      npm/ng-packs/packages/oauth/src/lib/services/memory-token-storage.service.ts
  2. 6
      npm/ng-packs/packages/oauth/src/lib/services/oauth.service.ts

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

@ -6,35 +6,31 @@ import { AbpLocalStorageService } from '@abp/ng.core';
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 keysShouldStoreInMemory = ['access_token', 'id_token', 'expires_at', 'id_token_claims_obj', 'id_token_expires_at', 'id_token_stored_at', 'access_token_stored_at', 'abpOAuthClientId', 'granted_scopes'];
private data = new Map<string, string>();
private localStorageService = inject(AbpLocalStorageService);
getItem(key: string): string {
console.log('getItem -->>', key);
if (this.keysShouldStoreInMemory.includes(key)) {
return this.data.get(key) || null;
if (!this.keysShouldStoreInMemory.includes(key)) {
return this.localStorageService.getItem(key);
}
return this.localStorageService.getItem(key);
return this.data.get(key) || null;
}
removeItem(key: string): void {
if (this.keysShouldStoreInMemory.includes(key)) {
this.data.delete(key);
if (!this.keysShouldStoreInMemory.includes(key)) {
this.localStorageService.removeItem(key);
return;
}
this.localStorageService.removeItem(key);
this.data.delete(key);
}
setItem(key: string, data: string): void {
if (this.keysShouldStoreInMemory.includes(key)) {
console.log('setItem -->', key, data);
this.data.set(key, data);
if (!this.keysShouldStoreInMemory.includes(key)) {
this.localStorageService.setItem(key, data);
return;
}
console.log('setItem -->', key, data);
this.localStorageService.setItem(key, data);
this.data.set(key, data);
}
clear() {

6
npm/ng-packs/packages/oauth/src/lib/services/oauth.service.ts

@ -110,7 +110,11 @@ export class AbpOAuthService implements IAuthService {
this.document.defaultView?.location.replace('/authorize');
return Promise.resolve();
}
return this.oAuthService.refreshToken();
try {
return this.oAuthService.refreshToken();
} catch (error) {
return Promise.resolve();
}
}
getAccessTokenExpiration(): number {

Loading…
Cancel
Save