diff --git a/npm/ng-packs/packages/core/src/lib/core.module.ts b/npm/ng-packs/packages/core/src/lib/core.module.ts index bcc071185f..4bf3fae3a1 100644 --- a/npm/ng-packs/packages/core/src/lib/core.module.ts +++ b/npm/ng-packs/packages/core/src/lib/core.module.ts @@ -3,7 +3,7 @@ import { HTTP_INTERCEPTORS, HttpClientModule, HttpClientXsrfModule } from '@angu import { APP_INITIALIZER, Injector, ModuleWithProviders, NgModule } from '@angular/core'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { RouterModule } from '@angular/router'; -import { OAuthModule, OAuthStorage } from 'angular-oauth2-oidc'; +import { OAuthModule, OAuthService, OAuthStorage } from 'angular-oauth2-oidc'; import { AbstractNgModelComponent } from './abstracts/ng-model.component'; import { DynamicLayoutComponent } from './components/dynamic-layout.component'; import { ReplaceableRouteContainerComponent } from './components/replaceable-route-container.component'; @@ -37,6 +37,7 @@ import { getInitialData, localeInitializer } from './utils/initial-utils'; import { ShortDateTimePipe } from './pipes/short-date-time.pipe'; import { ShortTimePipe } from './pipes/short-time.pipe'; import { ShortDatePipe } from './pipes/short-date.pipe'; +import { TimeoutLimitedOAuthService } from './services/timeout-limited-oauth.service'; export function storageFactory(): OAuthStorage { return oAuthStorage; @@ -184,6 +185,7 @@ export class CoreModule { useFactory: noop, }, { provide: OAuthStorage, useFactory: storageFactory }, + { provide: OAuthService, useClass: TimeoutLimitedOAuthService }, { provide: TENANT_KEY, useValue: options.tenantKey || '__tenant' }, { provide: LOCALIZATIONS, diff --git a/npm/ng-packs/packages/core/src/lib/services/index.ts b/npm/ng-packs/packages/core/src/lib/services/index.ts index 6f20399fce..7584316db0 100644 --- a/npm/ng-packs/packages/core/src/lib/services/index.ts +++ b/npm/ng-packs/packages/core/src/lib/services/index.ts @@ -19,3 +19,4 @@ export * from './routes.service'; export * from './session-state.service'; export * from './subscription.service'; export * from './track-by.service'; +export * from './timeout-limited-oauth.service'; diff --git a/npm/ng-packs/packages/core/src/lib/services/timeout-limited-oauth.service.ts b/npm/ng-packs/packages/core/src/lib/services/timeout-limited-oauth.service.ts new file mode 100644 index 0000000000..47b25ba306 --- /dev/null +++ b/npm/ng-packs/packages/core/src/lib/services/timeout-limited-oauth.service.ts @@ -0,0 +1,13 @@ +import { Injectable } from '@angular/core'; +import { OAuthService } from 'angular-oauth2-oidc'; + +@Injectable() +export class TimeoutLimitedOAuthService extends OAuthService { + protected override calcTimeout(storedAt: number, expiration: number): number { + const now = this.dateTimeService.now(); + const delta = (expiration - storedAt) * this.timeoutFactor - (now - storedAt); + const result = Math.max(0, delta); + const MAX_TIMEOUT_DURATION = 2147483647; + return result < MAX_TIMEOUT_DURATION ? result : MAX_TIMEOUT_DURATION - 1; + } +}