Browse Source

fix: resolve the problem of redirecting to the swagger

resolves https://github.com/volosoft/volo/issues/3230
pull/5358/head
mehmet-erim 6 years ago
parent
commit
addce51490
  1. 3
      npm/ng-packs/packages/core/src/lib/core.module.ts
  2. 41
      npm/ng-packs/packages/core/src/lib/strategies/auth-flow.strategy.ts

3
npm/ng-packs/packages/core/src/lib/core.module.ts

@ -43,9 +43,10 @@ import { coreOptionsFactory, CORE_OPTIONS } from './tokens/options.token';
import { noop } from './utils/common-utils';
import './utils/date-extensions';
import { getInitialData, localeInitializer } from './utils/initial-utils';
import { oAuthStorage } from './strategies/auth-flow.strategy';
export function storageFactory(): OAuthStorage {
return localStorage;
return oAuthStorage;
}
/**

41
npm/ng-packs/packages/core/src/lib/strategies/auth-flow.strategy.ts

@ -1,7 +1,7 @@
import { Injector } from '@angular/core';
import { Router } from '@angular/router';
import { Store } from '@ngxs/store';
import { AuthConfig, OAuthService } from 'angular-oauth2-oidc';
import { AuthConfig, OAuthService, OAuthStorage } from 'angular-oauth2-oidc';
import { Observable, of } from 'rxjs';
import { switchMap, tap } from 'rxjs/operators';
import { GetAppConfiguration } from '../actions/config.actions';
@ -9,6 +9,8 @@ import { RestOccurError } from '../actions/rest.actions';
import { RestService } from '../services/rest.service';
import { ConfigState } from '../states/config.state';
export const oAuthStorage = localStorage;
export abstract class AuthFlowStrategy {
abstract readonly isInternalAuth: boolean;
@ -29,6 +31,12 @@ export abstract class AuthFlowStrategy {
}
async init(): Promise<any> {
const shouldClear = shouldStorageClear(
this.store.selectSnapshot(ConfigState.getDeep('environment.oAuthConfig.clientId')),
oAuthStorage,
);
if (shouldClear) clearOAuthStorage(oAuthStorage);
this.oAuthService.configure(this.oAuthConfig);
return this.oAuthService.loadDiscoveryDocument().catch(this.catchError);
}
@ -110,3 +118,34 @@ export const AUTH_FLOW_STRATEGY = {
return new AuthPasswordFlowStrategy(injector);
},
};
function clearOAuthStorage(storage: OAuthStorage) {
const keys = [
'access_token',
'id_token',
'refresh_token',
'nonce',
'PKCE_verifier',
'expires_at',
'id_token_claims_obj',
'id_token_expires_at',
'id_token_stored_at',
'access_token_stored_at',
'granted_scopes',
'session_state',
];
keys.forEach(key => storage.removeItem(key));
}
function shouldStorageClear(clientId: string, storage: OAuthStorage): boolean {
const key = 'abpOAuthClientId';
if (!storage.getItem(key)) {
storage.setItem(key, clientId);
return false;
}
const shouldClear = storage.getItem(key) !== clientId;
if (shouldClear) storage.setItem(key, clientId);
return shouldClear;
}

Loading…
Cancel
Save