UNPKG

@intuitionrobotics/user-account

Version:
60 lines 3.11 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SamlModule = exports.SamlModule_Class = void 0; const saml2_js_1 = require("saml2-js"); const ts_common_1 = require("@intuitionrobotics/ts-common"); class SamlModule_Class extends ts_common_1.Module { constructor() { super("SamlModule"); this.loginRequest = (loginContext) => __awaiter(this, void 0, void 0, function* () { return new Promise((resolve, rejected) => { const sp = new saml2_js_1.ServiceProvider(this.config.spConfig); const options = { relay_state: (0, ts_common_1.__stringify)(loginContext) }; sp.create_login_request_url(this.identityProvider, options, (error, loginUrl, requestId) => { if (error) return rejected(error); resolve(loginUrl); }); }); }); this.assert = (options) => __awaiter(this, void 0, void 0, function* () { return new Promise((resolve, rejected) => { const sp = new saml2_js_1.ServiceProvider(this.config.spConfig); sp.post_assert(this.identityProvider, options, (error, response) => __awaiter(this, void 0, void 0, function* () { if (error) return rejected(error); const userId = response.user.name_id; const relay_state = options.request_body.RelayState; if (!relay_state) return rejected(`LoginContext lost along the way for userId '${userId}'`); resolve({ userId: userId, loginContext: JSON.parse(relay_state), fullResponse: response }); })); }); }); } init() { if (!this.config.idConfig) throw new ts_common_1.ImplementationMissingException("Config must contain idConfig"); if (!this.config.spConfig) throw new ts_common_1.ImplementationMissingException("Config must contain spConfig"); this.identityProvider = new saml2_js_1.IdentityProvider(this.config.idConfig); } } exports.SamlModule_Class = SamlModule_Class; exports.SamlModule = new SamlModule_Class(); //# sourceMappingURL=SamlModule.js.map