UNPKG

oidc-client-rx

Version:

ReactiveX enhanced OIDC and OAuth2 protocol support for browser-based JavaScript applications

46 lines (45 loc) 2.65 kB
import { Injectable, inject } from "@outposts/injection-js"; import { map, of, switchMap } from "rxjs"; import { AuthWellKnownService } from "../../config/auth-well-known/auth-well-known.service.js"; import { FlowsDataService } from "../../flows/flows-data.service.js"; import { LoggerService } from "../../logging/logger.service.js"; import { RedirectService } from "../../utils/redirect/redirect.service.js"; import { UrlService } from "../../utils/url/url.service.js"; import { ResponseTypeValidationService } from "../response-type-validation/response-type-validation.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 StandardLoginService { loginStandard(configuration, authOptions) { if (!this.responseTypeValidationService.hasConfigValidResponseType(configuration)) { this.loggerService.logError(configuration, 'Invalid response type!'); return of(void 0); } this.loggerService.logDebug(configuration, 'BEGIN Authorize OIDC Flow, no auth data'); this.flowsDataService.setCodeFlowInProgress(configuration); return this.authWellKnownService.queryAndStoreAuthWellKnownEndPoints(configuration).pipe(switchMap(()=>{ this.flowsDataService.resetSilentRenewRunning(configuration); return this.urlService.getAuthorizeUrl(configuration, authOptions); }), map((url)=>{ const { urlHandler } = authOptions || {}; if (!url) return void this.loggerService.logError(configuration, 'Could not create URL', url); if (urlHandler) urlHandler(url); else this.redirectService.redirectTo(url); })); } constructor(){ this.loggerService = inject(LoggerService); this.responseTypeValidationService = inject(ResponseTypeValidationService); this.urlService = inject(UrlService); this.redirectService = inject(RedirectService); this.authWellKnownService = inject(AuthWellKnownService); this.flowsDataService = inject(FlowsDataService); } } StandardLoginService = _ts_decorate([ Injectable() ], StandardLoginService); export { StandardLoginService };