mirror of https://github.com/abpframework/abp.git
12 changed files with 47 additions and 68 deletions
@ -0,0 +1,6 @@ |
|||||
|
import { InjectionToken } from '@angular/core'; |
||||
|
import { CheckAuthenticationStateFn } from '@abp/ng.core'; |
||||
|
|
||||
|
export const CHECK_AUTHENTICATION_STATE_FN_KEY = new InjectionToken<CheckAuthenticationStateFn>( |
||||
|
'CHECK_AUTHENTICATION_STATE_FN_KEY', |
||||
|
); |
||||
@ -1,12 +0,0 @@ |
|||||
import { Injectable } from '@angular/core'; |
|
||||
import { OAuthService } from 'angular-oauth2-oidc'; |
|
||||
|
|
||||
/** * @deprecated No need to override official service. It should be fixed in 15 or never version of angular-oauth2-oidc*/ |
|
||||
@Injectable() |
|
||||
export class TimeoutLimitedOAuthService extends OAuthService { |
|
||||
protected override calcTimeout(storedAt: number, expiration: number): number { |
|
||||
const result = super.calcTimeout(storedAt, expiration); |
|
||||
const MAX_TIMEOUT_DURATION = 2147483647; |
|
||||
return result < MAX_TIMEOUT_DURATION ? result : MAX_TIMEOUT_DURATION - 1; |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,12 @@ |
|||||
|
import { Injector } from '@angular/core'; |
||||
|
import { CheckAuthenticationStateFn, ConfigStateService } from '@abp/ng.core'; |
||||
|
import { OAuthService } from 'angular-oauth2-oidc'; |
||||
|
import { clearOAuthStorage } from './clear-o-auth-storage'; |
||||
|
|
||||
|
export const checkAccessToken: CheckAuthenticationStateFn = function (injector: Injector) { |
||||
|
const configState = injector.get(ConfigStateService); |
||||
|
const oAuth = injector.get(OAuthService); |
||||
|
if (oAuth.hasValidAccessToken() && !configState.getDeep('currentUser.id')) { |
||||
|
clearOAuthStorage(); |
||||
|
} |
||||
|
}; |
||||
@ -1,31 +0,0 @@ |
|||||
import { ABP, AuthService, ConfigStateService, CORE_OPTIONS } from '@abp/ng.core'; |
|
||||
import { Injector } from '@angular/core'; |
|
||||
import { OAuthService } from 'angular-oauth2-oidc'; |
|
||||
import { clearOAuthStorage } from './clear-o-auth-storage'; |
|
||||
import { lastValueFrom } from 'rxjs'; |
|
||||
import { tap } from 'rxjs/operators'; |
|
||||
|
|
||||
export function initFactory(injector: Injector): () => Promise<void> { |
|
||||
return async () => { |
|
||||
const authService = injector.get(AuthService); |
|
||||
await authService.init(); |
|
||||
const configState = injector.get(ConfigStateService); |
|
||||
|
|
||||
const options = injector.get(CORE_OPTIONS) as ABP.Root; |
|
||||
|
|
||||
if (options.skipGetAppConfiguration) { |
|
||||
return; |
|
||||
} |
|
||||
|
|
||||
const result$ = configState.refreshAppState().pipe(tap(() => checkAccessToken(injector))); |
|
||||
await lastValueFrom(result$); |
|
||||
}; |
|
||||
} |
|
||||
|
|
||||
export function checkAccessToken(injector: Injector) { |
|
||||
const configState = injector.get(ConfigStateService); |
|
||||
const oAuth = injector.get(OAuthService); |
|
||||
if (oAuth.hasValidAccessToken() && !configState.getDeep('currentUser.id')) { |
|
||||
clearOAuthStorage(); |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue