UNPKG

oidc-client-rx

Version:

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

60 lines (59 loc) 3.47 kB
import { Injectable, inject } from "injection-js"; import { BehaviorSubject, of, throwError } from "rxjs"; import { MockUtil } from "../utils/reflect/index.js"; import { StoragePersistenceService } from "../storage/storage-persistence.service.js"; import { ParLoginService } from "./par/par-login.service.js"; import { PopUpService } from "./popup/popup.service.js"; import { PopUpLoginService } from "./popup/popup-login.service.js"; import { StandardLoginService } from "./standard/standard-login.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; } function _ts_metadata(k, v) { if ("object" == typeof Reflect && "function" == typeof Reflect.metadata) return Reflect.metadata(k, v); } class LoginService { login(configuration, authOptions) { if (!configuration) return throwError(()=>new Error("Please provide a configuration before setting up the module")); const { usePushedAuthorisationRequests } = configuration; if (authOptions?.customParams) this.storagePersistenceService.write("storageCustomParamsAuthRequest", authOptions.customParams, configuration); if (usePushedAuthorisationRequests) return this.parLoginService.loginPar(configuration, authOptions); return this.standardLoginService.loginStandard(configuration, authOptions); } loginWithPopUp(configuration, allConfigs, authOptions, popupOptions) { if (!configuration) throw new Error("Please provide a configuration before setting up the module"); const isAlreadyInPopUp = this.popupService.isCurrentlyInPopup(configuration); if (isAlreadyInPopUp) return of({ errorMessage: "There is already a popup open." }); const { usePushedAuthorisationRequests } = configuration; if (authOptions?.customParams) this.storagePersistenceService.write("storageCustomParamsAuthRequest", authOptions.customParams, configuration); if (usePushedAuthorisationRequests) return this.parLoginService.loginWithPopUpPar(configuration, allConfigs, authOptions, popupOptions); return this.popUpLoginService.loginWithPopUpStandard(configuration, allConfigs, authOptions, popupOptions); } constructor(){ this.parLoginService = inject(ParLoginService); this.popUpLoginService = inject(PopUpLoginService); this.standardLoginService = inject(StandardLoginService); this.storagePersistenceService = inject(StoragePersistenceService); this.popupService = inject(PopUpService); } } _ts_decorate([ MockUtil({ implementation: ()=>new BehaviorSubject(void 0) }), _ts_metadata("design:type", Function), _ts_metadata("design:paramtypes", [ Object, "u" < typeof AuthOptions ? Object : AuthOptions ]), _ts_metadata("design:returntype", "u" < typeof Observable ? Object : Observable) ], LoginService.prototype, "login", null); LoginService = _ts_decorate([ Injectable() ], LoginService); export { LoginService };