Browse Source

reduce token expiration timeout

pull/14137/head
muhammedaltug 3 years ago
parent
commit
0f691dfe85
  1. 4
      npm/ng-packs/packages/core/src/lib/core.module.ts
  2. 1
      npm/ng-packs/packages/core/src/lib/services/index.ts
  3. 13
      npm/ng-packs/packages/core/src/lib/services/timeout-limited-oauth.service.ts

4
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,

1
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';

13
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;
}
}
Loading…
Cancel
Save