|
|
|
@ -1,19 +1,23 @@ |
|
|
|
import { Injectable, Injector, inject } from '@angular/core'; |
|
|
|
import { Injectable, Injector, inject, PLATFORM_ID, DOCUMENT } from '@angular/core'; |
|
|
|
import { Params } from '@angular/router'; |
|
|
|
import { from, Observable, lastValueFrom, EMPTY } from 'rxjs'; |
|
|
|
import { filter, map, switchMap, take, tap } from 'rxjs/operators'; |
|
|
|
import { AbpAuthResponse, IAuthService, LoginParams } from '@abp/ng.core'; |
|
|
|
import { AbpAuthResponse, APP_STARTED_WITH_SSR, IAuthService, LoginParams } from '@abp/ng.core'; |
|
|
|
import { AuthFlowStrategy } from '../strategies'; |
|
|
|
import { EnvironmentService } from '@abp/ng.core'; |
|
|
|
import { AUTH_FLOW_STRATEGY } from '../tokens/auth-flow-strategy'; |
|
|
|
import { OAuthService } from 'angular-oauth2-oidc'; |
|
|
|
import { HttpHeaders } from '@angular/common/http'; |
|
|
|
import { isPlatformBrowser } from '@angular/common'; |
|
|
|
|
|
|
|
@Injectable({ |
|
|
|
providedIn: 'root', |
|
|
|
}) |
|
|
|
export class AbpOAuthService implements IAuthService { |
|
|
|
protected injector = inject(Injector); |
|
|
|
private appStartedWithSsr = this.injector.get(APP_STARTED_WITH_SSR); |
|
|
|
private platformId = this.injector.get(PLATFORM_ID); |
|
|
|
private document = this.injector.get(DOCUMENT); |
|
|
|
|
|
|
|
private strategy!: AuthFlowStrategy; |
|
|
|
private readonly oAuthService: OAuthService; |
|
|
|
@ -57,7 +61,7 @@ export class AbpOAuthService implements IAuthService { |
|
|
|
if (!this.strategy) { |
|
|
|
return EMPTY; |
|
|
|
} |
|
|
|
|
|
|
|
console.log("logout called with queryParams:", queryParams); |
|
|
|
return this.strategy.logout(queryParams); |
|
|
|
} |
|
|
|
|
|
|
|
@ -70,6 +74,7 @@ export class AbpOAuthService implements IAuthService { |
|
|
|
} |
|
|
|
|
|
|
|
get isAuthenticated(): boolean { |
|
|
|
console.log("isAuthenticated --->>>", this.oAuthService.hasValidAccessToken()); |
|
|
|
return this.oAuthService.hasValidAccessToken(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -102,7 +107,11 @@ export class AbpOAuthService implements IAuthService { |
|
|
|
return this.oAuthService.getAccessToken(); |
|
|
|
} |
|
|
|
|
|
|
|
refreshToken(): Promise<AbpAuthResponse> { |
|
|
|
refreshToken(): Promise<AbpAuthResponse | void> { |
|
|
|
if (isPlatformBrowser(this.platformId) && this.appStartedWithSsr) { |
|
|
|
this.document.defaultView?.location.replace('/authorize'); |
|
|
|
return Promise.resolve(); |
|
|
|
} |
|
|
|
return this.oAuthService.refreshToken(); |
|
|
|
} |
|
|
|
|
|
|
|
|