oidc-client-rx
Version:
ReactiveX enhanced OIDC and OAuth2 protocol support for browser-based JavaScript applications
43 lines (42 loc) • 2.44 kB
JavaScript
import { Injectable, inject } from "injection-js";
import { throwError } from "rxjs";
import { catchError, tap } from "rxjs/operators";
import { FlowsService } from "../flows/flows.service.js";
import { FlowsDataService } from "../flows/flows-data.service.js";
import { injectAbstractType } from "../injection/index.js";
import { AbstractRouter } from "../router/index.js";
import { IntervalService } from "./interval.service.js";
function _ts_decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : null === desc ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(decorators, target, key, desc);
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
class CodeFlowCallbackService {
authenticatedCallbackWithCode(urlToCheck, config, allConfigs) {
const isRenewProcess = this.flowsDataService.isSilentRenewRunning(config);
const { triggerAuthorizationResultEvent } = config;
const postLoginRoute = config.postLoginRoute || "/";
const unauthorizedRoute = config.unauthorizedRoute || "/";
return this.flowsService.processCodeFlowCallback(urlToCheck, config, allConfigs).pipe(tap((callbackContext)=>{
this.flowsDataService.resetCodeFlowInProgress(config);
if (!triggerAuthorizationResultEvent && !callbackContext.isRenewProcess) this.router.navigateByUrl(postLoginRoute);
}), catchError((error)=>{
this.flowsDataService.resetSilentRenewRunning(config);
this.flowsDataService.resetCodeFlowInProgress(config);
this.intervalService.stopPeriodicTokenCheck();
if (!triggerAuthorizationResultEvent && !isRenewProcess) this.router.navigateByUrl(unauthorizedRoute);
return throwError(()=>new Error(error));
}));
}
constructor(){
this.flowsService = inject(FlowsService);
this.router = injectAbstractType(AbstractRouter);
this.flowsDataService = inject(FlowsDataService);
this.intervalService = inject(IntervalService);
}
}
CodeFlowCallbackService = _ts_decorate([
Injectable()
], CodeFlowCallbackService);
export { CodeFlowCallbackService };