mirror of https://github.com/abpframework/abp.git
3 changed files with 38 additions and 9 deletions
@ -1 +1,2 @@ |
|||||
|
export * from './oauth-configuration.handler'; |
||||
export * from './routes.handler'; |
export * from './routes.handler'; |
||||
|
|||||
@ -0,0 +1,35 @@ |
|||||
|
import { Inject, Injectable } from '@angular/core'; |
||||
|
import { Actions, ofActionSuccessful } from '@ngxs/store'; |
||||
|
import { OAuthService } from 'angular-oauth2-oidc'; |
||||
|
import compare from 'just-compare'; |
||||
|
import { filter, map } from 'rxjs/operators'; |
||||
|
import { SetEnvironment } from '../actions/config.actions'; |
||||
|
import { ABP } from '../models/common'; |
||||
|
import { CORE_OPTIONS } from '../tokens/options.token'; |
||||
|
|
||||
|
@Injectable({ |
||||
|
providedIn: 'root', |
||||
|
}) |
||||
|
export class OAuthConfigurationHandler { |
||||
|
constructor( |
||||
|
private actions: Actions, |
||||
|
private oAuthService: OAuthService, |
||||
|
@Inject(CORE_OPTIONS) private options: ABP.Root, |
||||
|
) { |
||||
|
this.oAuthService.configure(this.options.environment.oAuthConfig); |
||||
|
|
||||
|
this.listenToSetEnvironment(); |
||||
|
} |
||||
|
|
||||
|
private listenToSetEnvironment() { |
||||
|
this.actions |
||||
|
.pipe(ofActionSuccessful(SetEnvironment)) |
||||
|
.pipe( |
||||
|
map(({ environment }: SetEnvironment) => environment.oAuthConfig), |
||||
|
filter(config => !compare(config, this.options.environment.oAuthConfig)), |
||||
|
) |
||||
|
.subscribe(config => { |
||||
|
this.oAuthService.configure(config); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue