File

C:/GoDev/src/TCSTK-Angular/projects/tibco-tcstk/tc-core-lib/src/lib/services/session-refresh-service.ts

Index

Properties
Methods

Constructor

constructor(http: HttpClient)
Parameters :
Name Type Optional
http HttpClient No

Methods

Public normalTokenRefresh
normalTokenRefresh()
Returns : Observable<any>
Public proxyTokenRefresh
proxyTokenRefresh()
Returns : Observable<any>
Public scheduleCookieRefresh
scheduleCookieRefresh(delay: number, usingProxy: boolean)
Parameters :
Name Type Optional
delay number No
usingProxy boolean No
Returns : void

Properties

Private delay
Type : number
Private normalRefreshFunction
Default value : () => {...}
Private proxiedRefreshFunction
Default value : () => {...}
import { Injectable } from '@angular/core';
import {tap} from 'rxjs/operators';
import {HttpClient} from '@angular/common/http';
import {Observable} from 'rxjs';


@Injectable({
  providedIn: 'root'
})

export class SessionRefreshService {

  constructor(private http: HttpClient) { }

  private delay: number;

  public scheduleCookieRefresh(delay: number, usingProxy: boolean) {
    this.delay = delay;
    const refreshFunction = usingProxy ? this.proxiedRefreshFunction : this.normalRefreshFunction;
    setInterval(refreshFunction, delay);
  }

  private proxiedRefreshFunction = () => {
    this.proxyTokenRefresh().pipe(
      tap( val => sessionStorage.setItem('tcsTimestamp', Date.now().toString()))
    ).subscribe();
  }

  private normalRefreshFunction = () => {
    this.normalTokenRefresh().pipe(
      tap( val => sessionStorage.setItem('tcsTimestamp', Date.now().toString()))
    ).subscribe();
  }

  public proxyTokenRefresh(): Observable<any> {
    const url = '/tokenRefresh';
    return this.http.get(url)
      .pipe(
        tap( val => sessionStorage.setItem('tcsTimestamp', Date.now().toString()))
      );
  }

  public normalTokenRefresh(): Observable<any> {
    const url = '/organisation/v1/claims';
    return this.http.get(url)
      .pipe(
        tap( val => sessionStorage.setItem('tcsTimestamp', Date.now().toString()))
      );
  }

}

result-matching ""

    No results matching ""