Browse Source

Merge pull request #5611 from abpframework/fix/logout-problem

Fixed the redirecting the logout page problem when the isAuthenticated is false
pull/5615/head
Mehmet Erim 6 years ago
committed by GitHub
parent
commit
b2291e9b60
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      npm/ng-packs/packages/core/src/lib/strategies/auth-flow.strategy.ts
  2. 7
      npm/ng-packs/packages/core/src/lib/tests/initial-utils.spec.ts
  3. 3
      npm/ng-packs/packages/core/src/lib/utils/initial-utils.ts

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

@ -119,7 +119,7 @@ export const AUTH_FLOW_STRATEGY = {
},
};
function clearOAuthStorage(storage: OAuthStorage) {
export function clearOAuthStorage(storage: OAuthStorage = oAuthStorage) {
const keys = [
'access_token',
'id_token',

7
npm/ng-packs/packages/core/src/lib/tests/initial-utils.spec.ts

@ -4,6 +4,7 @@ import { Store } from '@ngxs/store';
import { OAuthService } from 'angular-oauth2-oidc';
import { of } from 'rxjs';
import { GetAppConfiguration } from '../actions';
import * as AuthFlowStrategy from '../strategies/auth-flow.strategy';
import { CORE_OPTIONS } from '../tokens/options.token';
import { checkAccessToken, getInitialData, localeInitializer } from '../utils';
import * as environmentUtils from '../utils/environment-utils';
@ -54,9 +55,9 @@ describe('InitialUtils', () => {
test('should call logOut fn of OAuthService when token is valid and current user not found', async () => {
const injector = spectator.inject(Injector);
const injectorSpy = jest.spyOn(injector, 'get');
const logOutFn = jest.fn();
const clearOAuthStorageSpy = jest.spyOn(AuthFlowStrategy, 'clearOAuthStorage');
injectorSpy.mockReturnValue({ hasValidAccessToken: () => true, logOut: logOutFn });
injectorSpy.mockReturnValue({ hasValidAccessToken: () => true });
checkAccessToken(
{
@ -64,7 +65,7 @@ describe('InitialUtils', () => {
} as any,
injector,
);
expect(logOutFn).toHaveBeenCalled();
expect(clearOAuthStorageSpy).toHaveBeenCalled();
});
});

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

@ -7,6 +7,7 @@ import { GetAppConfiguration } from '../actions/config.actions';
import { ABP } from '../models/common';
import { AuthService } from '../services/auth.service';
import { ConfigState } from '../states/config.state';
import { clearOAuthStorage } from '../strategies/auth-flow.strategy';
import { CORE_OPTIONS } from '../tokens/options.token';
import { getRemoteEnv } from './environment-utils';
import { parseTenantFromUrl } from './multi-tenancy-utils';
@ -34,7 +35,7 @@ export function getInitialData(injector: Injector) {
export function checkAccessToken(store: Store, injector: Injector) {
const oAuth = injector.get(OAuthService);
if (oAuth.hasValidAccessToken() && !store.selectSnapshot(ConfigState.getDeep('currentUser.id'))) {
oAuth.logOut();
clearOAuthStorage();
}
}

Loading…
Cancel
Save