UNPKG

oidc-client-rx

Version:

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

54 lines (53 loc) 3.1 kB
import { Injectable, inject } from "injection-js"; import { of, throwError } from "rxjs"; import { switchMap, take, tap } from "rxjs/operators"; import { CheckAuthService } from "../../auth-state/check-auth.service.js"; import { AuthWellKnownService } from "../../config/auth-well-known/auth-well-known.service.js"; import { LoggerService } from "../../logging/logger.service.js"; import { UrlService } from "../../utils/url/url.service.js"; import { ResponseTypeValidationService } from "../response-type-validation/response-type-validation.service.js"; import { PopUpService } from "./popup.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 PopUpLoginService { loginWithPopUpStandard(configuration, allConfigs, authOptions, popupOptions) { const { configId } = configuration; if (!this.responseTypeValidationService.hasConfigValidResponseType(configuration)) { const errorMessage = "Invalid response type!"; this.loggerService.logError(configuration, errorMessage); return throwError(()=>new Error(errorMessage)); } this.loggerService.logDebug(configuration, "BEGIN Authorize OIDC Flow with popup, no auth data"); return this.authWellKnownService.queryAndStoreAuthWellKnownEndPoints(configuration).pipe(switchMap(()=>this.urlService.getAuthorizeUrl(configuration, authOptions)), tap((authUrl)=>this.popupService.openPopUp(authUrl, popupOptions, configuration)), switchMap(()=>this.popupService.result$.pipe(take(1), switchMap((result)=>{ const { userClosed, receivedUrl } = result; if (userClosed) { const response = { isAuthenticated: false, errorMessage: "User closed popup", userData: null, idToken: "", accessToken: "", configId }; return of(response); } return this.checkAuthService.checkAuth(configuration, allConfigs, receivedUrl); })))); } constructor(){ this.loggerService = inject(LoggerService); this.responseTypeValidationService = inject(ResponseTypeValidationService); this.urlService = inject(UrlService); this.authWellKnownService = inject(AuthWellKnownService); this.popupService = inject(PopUpService); this.checkAuthService = inject(CheckAuthService); } } PopUpLoginService = _ts_decorate([ Injectable() ], PopUpLoginService); export { PopUpLoginService };