|
|
|
@ -1,5 +1,5 @@ |
|
|
|
import { Injector, PLATFORM_ID } from '@angular/core'; |
|
|
|
import { noop } from '@abp/ng.core'; |
|
|
|
import { DOCUMENT, Injector, PLATFORM_ID } from '@angular/core'; |
|
|
|
import { APP_STARTED_WITH_SSR, noop } from '@abp/ng.core'; |
|
|
|
import { Params } from '@angular/router'; |
|
|
|
import { filter, from, of, take, tap } from 'rxjs'; |
|
|
|
import { AuthFlowStrategy } from './auth-flow-strategy'; |
|
|
|
@ -9,25 +9,27 @@ import { isPlatformBrowser } from '@angular/common'; |
|
|
|
export class AuthCodeFlowStrategy extends AuthFlowStrategy { |
|
|
|
readonly isInternalAuth = false; |
|
|
|
private platformId: object; |
|
|
|
protected appStartedWithSSR: boolean; |
|
|
|
protected document: Document; |
|
|
|
|
|
|
|
constructor(protected injector: Injector) { |
|
|
|
super(injector); |
|
|
|
this.platformId = injector.get(PLATFORM_ID); |
|
|
|
this.appStartedWithSSR = injector.get(APP_STARTED_WITH_SSR); |
|
|
|
this.document = injector.get(DOCUMENT); |
|
|
|
} |
|
|
|
|
|
|
|
async init() { |
|
|
|
this.checkRememberMeOption(); |
|
|
|
this.listenToTokenReceived(); |
|
|
|
|
|
|
|
return super |
|
|
|
.init() |
|
|
|
.then(() => this.oAuthService.tryLogin().catch(noop)) |
|
|
|
.then(() => { |
|
|
|
//TODO:Investigate silent refresh issue in SSR
|
|
|
|
if (isPlatformBrowser(this.platformId)) { |
|
|
|
if (!this.appStartedWithSSR && isPlatformBrowser(this.platformId)) { |
|
|
|
return super |
|
|
|
.init() |
|
|
|
.then(() => this.oAuthService.tryLogin().catch(noop)) |
|
|
|
.then(() => { |
|
|
|
this.oAuthService.setupAutomaticSilentRefresh(); |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private checkRememberMeOption() { |
|
|
|
@ -78,11 +80,12 @@ export class AuthCodeFlowStrategy extends AuthFlowStrategy { |
|
|
|
} |
|
|
|
|
|
|
|
protected listenToTokenReceived() { |
|
|
|
if (isPlatformBrowser(this.platformId)) { |
|
|
|
if (isPlatformBrowser(this.platformId) && !this.appStartedWithSSR) { |
|
|
|
this.oAuthService.events |
|
|
|
.pipe( |
|
|
|
filter(event => event.type === 'token_received'), |
|
|
|
tap(() => { |
|
|
|
//TODO: Investigate how to handle with ssr
|
|
|
|
this.setUICulture(); |
|
|
|
this.replaceURLParams(); |
|
|
|
}), |
|
|
|
@ -94,13 +97,19 @@ export class AuthCodeFlowStrategy extends AuthFlowStrategy { |
|
|
|
|
|
|
|
navigateToLogin(queryParams?: Params) { |
|
|
|
if (isPlatformBrowser(this.platformId)) { |
|
|
|
let additionalState = ''; |
|
|
|
if (queryParams?.returnUrl) { |
|
|
|
additionalState = queryParams.returnUrl; |
|
|
|
} |
|
|
|
if (APP_STARTED_WITH_SSR) { |
|
|
|
if (this.document.defaultView) { |
|
|
|
this.document.defaultView.location.replace('/authorize'); |
|
|
|
} |
|
|
|
} else { |
|
|
|
let additionalState = ''; |
|
|
|
if (queryParams?.returnUrl) { |
|
|
|
additionalState = queryParams.returnUrl; |
|
|
|
} |
|
|
|
|
|
|
|
const cultureParams = this.getCultureParams(queryParams); |
|
|
|
this.oAuthService.initCodeFlow(additionalState, cultureParams); |
|
|
|
const cultureParams = this.getCultureParams(queryParams); |
|
|
|
this.oAuthService.initCodeFlow(additionalState, cultureParams); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -113,11 +122,18 @@ export class AuthCodeFlowStrategy extends AuthFlowStrategy { |
|
|
|
|
|
|
|
logout(queryParams?: Params) { |
|
|
|
this.rememberMeService.remove(); |
|
|
|
if (queryParams?.noRedirectToLogoutUrl) { |
|
|
|
this.router.navigate(['/']); |
|
|
|
return from(this.oAuthService.revokeTokenAndLogout(true)); |
|
|
|
|
|
|
|
if (APP_STARTED_WITH_SSR) { |
|
|
|
if (this.document.defaultView) { |
|
|
|
this.document.defaultView.location.replace('/logout'); |
|
|
|
} |
|
|
|
} else { |
|
|
|
if (queryParams?.noRedirectToLogoutUrl) { |
|
|
|
this.router.navigate(['/']); |
|
|
|
return from(this.oAuthService.revokeTokenAndLogout(true)); |
|
|
|
} |
|
|
|
return from(this.oAuthService.revokeTokenAndLogout(this.getCultureParams(queryParams))); |
|
|
|
} |
|
|
|
return from(this.oAuthService.revokeTokenAndLogout(this.getCultureParams(queryParams))); |
|
|
|
} |
|
|
|
|
|
|
|
login(queryParams?: Params) { |
|
|
|
|