|
|
|
@ -2,7 +2,13 @@ import { HttpHeaders } from '@angular/common/http'; |
|
|
|
import { Injector } from '@angular/core'; |
|
|
|
import { Params, Router } from '@angular/router'; |
|
|
|
import { Store } from '@ngxs/store'; |
|
|
|
import { AuthConfig, OAuthErrorEvent, OAuthInfoEvent, OAuthService, OAuthStorage } from 'angular-oauth2-oidc'; |
|
|
|
import { |
|
|
|
AuthConfig, |
|
|
|
OAuthErrorEvent, |
|
|
|
OAuthInfoEvent, |
|
|
|
OAuthService, |
|
|
|
OAuthStorage, |
|
|
|
} from 'angular-oauth2-oidc'; |
|
|
|
import { from, Observable, of } from 'rxjs'; |
|
|
|
import { filter, switchMap, tap } from 'rxjs/operators'; |
|
|
|
import { RestOccurError } from '../actions/rest.actions'; |
|
|
|
@ -32,10 +38,10 @@ export abstract class AuthFlowStrategy { |
|
|
|
protected sessionState: SessionStateService; |
|
|
|
protected appConfigService: AbpApplicationConfigurationService; |
|
|
|
|
|
|
|
abstract checkIfInternalAuth(): boolean; |
|
|
|
abstract checkIfInternalAuth(queryParams?: Params): boolean; |
|
|
|
abstract navigateToLogin(queryParams?: Params): void; |
|
|
|
abstract logout(queryParams?: Params): Observable<any>; |
|
|
|
abstract login(params?: LoginParams): Observable<any>; |
|
|
|
abstract login(params?: LoginParams | Params): Observable<any>; |
|
|
|
|
|
|
|
private catchError = err => this.store.dispatch(new RestOccurError(err)); |
|
|
|
|
|
|
|
@ -99,26 +105,28 @@ export class AuthCodeFlowStrategy extends AuthFlowStrategy { |
|
|
|
} |
|
|
|
|
|
|
|
navigateToLogin(queryParams?: Params) { |
|
|
|
const lang = this.sessionState.getLanguage(); |
|
|
|
const culture = { culture: lang, 'ui-culture': lang }; |
|
|
|
this.oAuthService.initCodeFlow(null, { ...(lang && culture), ...queryParams }); |
|
|
|
this.oAuthService.initCodeFlow('', this.getCultureParams(queryParams)); |
|
|
|
} |
|
|
|
|
|
|
|
checkIfInternalAuth() { |
|
|
|
this.oAuthService.initCodeFlow(); |
|
|
|
checkIfInternalAuth(queryParams?: Params) { |
|
|
|
this.oAuthService.initCodeFlow('', this.getCultureParams(queryParams)); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
logout(queryParams?: Params) { |
|
|
|
const lang = this.sessionState.getLanguage(); |
|
|
|
const culture = { culture: lang, 'ui-culture': lang }; |
|
|
|
return from(this.oAuthService.revokeTokenAndLogout({ ...(lang && culture), ...queryParams })); |
|
|
|
return from(this.oAuthService.revokeTokenAndLogout(this.getCultureParams(queryParams))); |
|
|
|
} |
|
|
|
|
|
|
|
login() { |
|
|
|
this.oAuthService.initCodeFlow(); |
|
|
|
login(queryParams?: Params) { |
|
|
|
this.oAuthService.initCodeFlow('', this.getCultureParams(queryParams)); |
|
|
|
return of(null); |
|
|
|
} |
|
|
|
|
|
|
|
private getCultureParams(queryParams?: Params) { |
|
|
|
const lang = this.sessionState.getLanguage(); |
|
|
|
const culture = { culture: lang, 'ui-culture': lang }; |
|
|
|
return { ...(lang && culture), ...queryParams }; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
export class AuthPasswordFlowStrategy extends AuthFlowStrategy { |
|
|
|
|