Browse Source

add a getter that returns the active auth strategy

pull/7861/head
mehmet-erim 6 years ago
parent
commit
2a7d3555d5
  1. 8
      npm/ng-packs/packages/account/src/lib/services/authentication.service.ts
  2. 11
      npm/ng-packs/packages/core/src/lib/services/auth.service.ts

8
npm/ng-packs/packages/account/src/lib/services/authentication.service.ts

@ -1,6 +1,8 @@
import { Inject, Injectable, Optional } from '@angular/core'; import { Inject, Injectable, Optional } from '@angular/core';
import { import {
AbpApplicationConfigurationService, AbpApplicationConfigurationService,
AuthPasswordFlowStrategy,
AuthService,
ConfigStateService, ConfigStateService,
RestService, RestService,
SessionStateService, SessionStateService,
@ -13,19 +15,18 @@ import { ACCOUNT_OPTIONS } from '../tokens/options.token';
import { Options } from '../models/options'; import { Options } from '../models/options';
import snq from 'snq'; import snq from 'snq';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { SessionHandler } from '@abp/ng.account/config';
@Injectable() @Injectable()
export class AuthenticationService { export class AuthenticationService {
constructor( constructor(
protected rest: RestService, protected rest: RestService,
protected sessionState: SessionStateService, protected sessionState: SessionStateService,
protected authService: AuthService,
protected oAuthService: OAuthService, protected oAuthService: OAuthService,
protected appConfigService: AbpApplicationConfigurationService, protected appConfigService: AbpApplicationConfigurationService,
protected configState: ConfigStateService, protected configState: ConfigStateService,
@Inject(ACCOUNT_OPTIONS) protected options: Options, @Inject(ACCOUNT_OPTIONS) protected options: Options,
protected router: Router, protected router: Router,
@Optional() protected sessionHandler: SessionHandler,
) {} ) {}
login(username: string, password: string, remember = false): Observable<any> { login(username: string, password: string, remember = false): Observable<any> {
@ -47,7 +48,8 @@ export class AuthenticationService {
this.router.navigate([redirectUrl]); this.router.navigate([redirectUrl]);
if (this.sessionHandler) this.sessionHandler.setRememberInfo(remember); const strategy = this.authService.activeAuthFlowStrategy;
if (strategy instanceof AuthPasswordFlowStrategy) strategy.setRememberMe(remember);
}), }),
take(1), take(1),
); );

11
npm/ng-packs/packages/core/src/lib/services/auth.service.ts

@ -1,6 +1,11 @@
import { Injectable, Injector } from '@angular/core'; import { Injectable, Injector } from '@angular/core';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { AuthFlowStrategy, AUTH_FLOW_STRATEGY } from '../strategies/auth-flow.strategy'; import {
AuthCodeFlowStrategy,
AuthFlowStrategy,
AuthPasswordFlowStrategy,
AUTH_FLOW_STRATEGY,
} from '../strategies/auth-flow.strategy';
import { EnvironmentService } from './environment.service'; import { EnvironmentService } from './environment.service';
@Injectable({ @Injectable({
@ -14,6 +19,10 @@ export class AuthService {
return this.strategy.isInternalAuth; return this.strategy.isInternalAuth;
} }
get activeAuthFlowStrategy() {
return this.strategy as AuthCodeFlowStrategy | AuthPasswordFlowStrategy;
}
constructor(private environment: EnvironmentService, private injector: Injector) { constructor(private environment: EnvironmentService, private injector: Injector) {
this.setStrategy(); this.setStrategy();
this.listenToSetEnvironment(); this.listenToSetEnvironment();

Loading…
Cancel
Save