UNPKG

@mvx/identity

Version:

identity is oidc for mvc, type-mvc is base on koa. Decorator, Ioc, AOP mvc framework on server.

78 lines (76 loc) 2.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OIDCUtils = void 0; var crypto = require("crypto"); var OIDCUtils; (function (OIDCUtils) { /** * Reconstructs the original URL of the request. * * This function builds a URL that corresponds the original URL requested by the * client, including the protocol (http or https) and host. * * If the request passed through any proxies that terminate SSL, the * `X-Forwarded-Proto` header is used to detect if the request was encrypted to * the proxy. * * @return {String} * @api private */ function originalURL(ctx, options) { var _a; options = options || {}; var app = ctx.app; if (app && ctx.get && ctx.get('trust proxy')) { options.proxy = true; } var trustProxy = options.proxy; var proto = (((_a = ctx.headers['x-forwarded-proto']) === null || _a === void 0 ? void 0 : _a.toString()) || '').toLowerCase(), tls = ctx.connection.encrypted || (trustProxy && 'https' === proto.split(/\s*,\s*/)[0]), host = (trustProxy && ctx.headers['x-forwarded-host']) || ctx.headers.host, protocol = tls ? 'https' : 'http', path = ctx.url || ''; return protocol + '://' + host + path; } OIDCUtils.originalURL = originalURL; ; /** * Merge object b with object a. * * var a = { foo: 'bar' } * , b = { bar: 'baz' }; * * utils.merge(a, b); * // => { foo: 'bar', bar: 'baz' } * * @param {Object} a * @param {Object} b * @return {Object} * @api private */ function merge(a, b) { if (a && b) { for (var key in b) { a[key] = b[key]; } } return a; } OIDCUtils.merge = merge; /** * Return a unique identifier with the given `len`. * * utils.uid(10); * // => "FDaS435D2z" * * CREDIT: Connect -- utils.uid * https://github.com/senchalabs/connect/blob/2.7.2/lib/utils.js * * @param {Number} len * @return {String} * @api private */ function uid(len) { return crypto.randomBytes(Math.ceil(len * 3 / 4)) .toString('base64') .slice(0, len); } OIDCUtils.uid = uid; })(OIDCUtils = exports.OIDCUtils || (exports.OIDCUtils = {})); //# sourceMappingURL=../sourcemaps/stores/utils.js.map