From 0e0af1e87244d05779343fae328cfd85ccc7d6ef Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Mon, 22 Feb 2021 14:11:50 +0300 Subject: [PATCH] update password flow logout method --- .../account/src/lib/account.module.ts | 16 ++++++------- .../lib/services/authentication.service.ts | 6 ++--- .../account/src/lib/utils/factory-utils.ts | 4 ++-- .../src/lib/strategies/auth-flow.strategy.ts | 24 ++++++------------- 4 files changed, 20 insertions(+), 30 deletions(-) diff --git a/npm/ng-packs/packages/account/src/lib/account.module.ts b/npm/ng-packs/packages/account/src/lib/account.module.ts index 255a8b3de5..20324d07cf 100644 --- a/npm/ng-packs/packages/account/src/lib/account.module.ts +++ b/npm/ng-packs/packages/account/src/lib/account.module.ts @@ -11,9 +11,9 @@ import { ManageProfileComponent } from './components/manage-profile/manage-profi import { PersonalSettingsComponent } from './components/personal-settings/personal-settings.component'; import { RegisterComponent } from './components/register/register.component'; import { TenantBoxComponent } from './components/tenant-box/tenant-box.component'; -import { Options } from './models/options'; -import { ACCOUNT_OPTIONS } from './tokens/options.token'; -import { accountOptionsFactory } from './utils/factory-utils'; +import { AccountConfigOptions } from './models/config-options'; +import { ACCOUNT_CONFIG_OPTIONS } from './tokens/config-options.token'; +import { accountConfigOptionsFactory } from './utils/factory-utils'; import { AuthenticationFlowGuard } from './guards/authentication-flow.guard'; import { AuthenticationService } from './services/authentication.service'; import { ForgotPasswordComponent } from './components/forgot-password/forgot-password.component'; @@ -43,23 +43,23 @@ const declarations = [ exports: [...declarations], }) export class AccountModule { - static forChild(options = {} as Options): ModuleWithProviders { + static forChild(options = {} as AccountConfigOptions): ModuleWithProviders { return { ngModule: AccountModule, providers: [ AuthenticationFlowGuard, AuthenticationService, - { provide: ACCOUNT_OPTIONS, useValue: options }, + { provide: ACCOUNT_CONFIG_OPTIONS, useValue: options }, { provide: 'ACCOUNT_OPTIONS', - useFactory: accountOptionsFactory, - deps: [ACCOUNT_OPTIONS], + useFactory: accountConfigOptionsFactory, + deps: [ACCOUNT_CONFIG_OPTIONS], }, ], }; } - static forLazy(options = {} as Options): NgModuleFactory { + static forLazy(options = {} as AccountConfigOptions): NgModuleFactory { return new LazyModuleFactory(AccountModule.forChild(options)); } } diff --git a/npm/ng-packs/packages/account/src/lib/services/authentication.service.ts b/npm/ng-packs/packages/account/src/lib/services/authentication.service.ts index ff5dd926e7..b49d1d8642 100644 --- a/npm/ng-packs/packages/account/src/lib/services/authentication.service.ts +++ b/npm/ng-packs/packages/account/src/lib/services/authentication.service.ts @@ -11,8 +11,8 @@ import { from, Observable } from 'rxjs'; import { OAuthService } from 'angular-oauth2-oidc'; import { HttpHeaders } from '@angular/common/http'; import { switchMap, take, tap } from 'rxjs/operators'; -import { ACCOUNT_OPTIONS } from '../tokens/options.token'; -import { Options } from '../models/options'; +import { ACCOUNT_CONFIG_OPTIONS } from '../tokens/config-options.token'; +import { AccountConfigOptions } from '../models/config-options'; import snq from 'snq'; import { Router } from '@angular/router'; @@ -25,7 +25,7 @@ export class AuthenticationService { protected oAuthService: OAuthService, protected appConfigService: AbpApplicationConfigurationService, protected configState: ConfigStateService, - @Inject(ACCOUNT_OPTIONS) protected options: Options, + @Inject(ACCOUNT_CONFIG_OPTIONS) protected options: AccountConfigOptions, protected router: Router, ) {} diff --git a/npm/ng-packs/packages/account/src/lib/utils/factory-utils.ts b/npm/ng-packs/packages/account/src/lib/utils/factory-utils.ts index 3e7c88f795..a04c1d4040 100644 --- a/npm/ng-packs/packages/account/src/lib/utils/factory-utils.ts +++ b/npm/ng-packs/packages/account/src/lib/utils/factory-utils.ts @@ -1,6 +1,6 @@ -import { Options } from '../models/options'; +import { AccountConfigOptions } from '../models/config-options'; -export function accountOptionsFactory(options: Options) { +export function accountConfigOptionsFactory(options: AccountConfigOptions) { return { redirectUrl: '/', ...options, diff --git a/npm/ng-packs/packages/core/src/lib/strategies/auth-flow.strategy.ts b/npm/ng-packs/packages/core/src/lib/strategies/auth-flow.strategy.ts index b50dd03d00..3aa894ff68 100644 --- a/npm/ng-packs/packages/core/src/lib/strategies/auth-flow.strategy.ts +++ b/npm/ng-packs/packages/core/src/lib/strategies/auth-flow.strategy.ts @@ -110,23 +110,13 @@ export class AuthPasswordFlowStrategy extends AuthFlowStrategy { } logout() { - const rest = this.injector.get(RestService); - - const issuer = this.configState.getDeep('environment.oAuthConfig.issuer'); - return rest - .request( - { - method: 'GET', - url: '/api/account/logout', - }, - null, - issuer, - ) - .pipe( - switchMap(() => from(this.oAuthService.revokeTokenAndLogout())), - switchMap(() => this.appConfigService.get()), - tap(res => this.configState.setState(res)), - ); + const router = this.injector.get(Router); + + return from(this.oAuthService.revokeTokenAndLogout()).pipe( + switchMap(() => this.appConfigService.get()), + tap(res => this.configState.setState(res)), + tap(() => router.navigateByUrl('/')), + ); } destroy() {}