UNPKG

@hmcts/rpx-xui-node-lib

Version:

Common nodejs library components for XUI

54 lines 2.69 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()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.oauth2 = exports.OAuth2 = void 0; const passport_1 = __importDefault(require("passport")); const oauth2_constants_1 = require("../oauth2.constants"); const models_1 = require("../../models"); const XUIOAuth2Strategy_class_1 = require("./XUIOAuth2Strategy.class"); const express_1 = require("express"); const common_1 = require("../../../common"); class OAuth2 extends models_1.Strategy { constructor(router = (0, express_1.Router)({ mergeParams: true }), logger = (0, common_1.getLogger)('auth:oauth2')) { super(oauth2_constants_1.OAUTH2.STRATEGY_NAME, router, logger); /** * Retrieve transformed AuthOptions * @param authOptions * @return OAuth2Metadata */ this.getOAuthOptions = (authOptions) => { const options = Object.assign(Object.assign({}, authOptions), { logoutUrl: authOptions.logoutURL, state: true, }); delete options.logoutURL; return options; }; this.initialiseStrategy = (authOptions) => __awaiter(this, void 0, void 0, function* () { this.logger.log('initialiseStrategy start'); const options = this.getOAuthOptions(authOptions); passport_1.default.use(this.strategyName, new XUIOAuth2Strategy_class_1.XUIOAuth2Strategy(options, this.verify)); this.logger.log('initialiseStrategy end'); }); this.verify = (accessToken, refreshToken, results, profile, done) => { done(null, { tokenset: { accessToken, refreshToken }, userinfo: profile }); }; } isInitialised() { return passport_1.default.strategies != null; } } exports.OAuth2 = OAuth2; exports.oauth2 = new OAuth2(); //# sourceMappingURL=oauth2.class.js.map