UNPKG

oauth-v2-client

Version:
48 lines (47 loc) 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var common_1 = require("@noreajs/common"); var helpers_1 = require("../helpers"); var GrantControl = /** @class */ (function () { function GrantControl(config) { var _a, _b; /** * Display errors in local data * @default `false` */ this.log = false; this.oauthOptions = config.oauthOptions; this.requestOptions = (_a = config.requestOptions) !== null && _a !== void 0 ? _a : {}; this.log = (_b = config.log) !== null && _b !== void 0 ? _b : false; } /** * Sign axios request config * @param options parameters */ GrantControl.prototype.sign = function (options) { // initial config var initialConfig = { baseURL: this.oauthOptions.apiBaseURL, headers: {}, }; // proxy if (options === null || options === void 0 ? void 0 : options.proxy) { initialConfig.headers["Proxy-Authorization"] = "".concat((0, helpers_1.capitalize)(options.token.token_type), " ").concat(options.token.access_token); } else { initialConfig.headers["Authorization"] = "".concat((0, helpers_1.capitalize)(options.token.token_type), " ").concat(options.token.access_token); } // sign function config var config = common_1.Obj.extend({ data: options, omits: ["proxy", "token"], }); return common_1.Obj.mergeNested({ left: config, right: initialConfig, priority: "left", }); }; return GrantControl; }()); exports.default = GrantControl;