@factset/sdk-utils
Version:
Utilities for interacting with FactSet APIs.
55 lines (54 loc) • 2.73 kB
JavaScript
;
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.OpenIDClientFactory = void 0;
const _1 = require(".");
const openid_client_1 = require("openid-client");
const debug_1 = __importDefault(require("debug"));
const constants_1 = require("./constants");
const debug = (0, debug_1.default)(`${constants_1.PACKAGE_NAME}:OpenIDClientFactory`);
class OpenIDClientFactory {
static getClient(config, proxyAgent) {
return __awaiter(this, void 0, void 0, function* () {
const jwks = {
keys: [config.jwk],
};
if (proxyAgent) {
openid_client_1.custom.setHttpOptionsDefaults({
agent: proxyAgent,
headers: {
'user-agent': `fds-sdk/javascript/utils/2.1.0 (${process.platform}; node ${process.version})`,
},
});
}
const clientAuthMethod = 'private_key_jwt';
const metadata = {
client_id: config.clientId,
token_endpoint_auth_method: clientAuthMethod,
};
const wellKnownUri = config.wellKnownUri;
try {
debug('Attempting metadata retrieval from well_known_uri: %s', config.wellKnownUri);
const issuer = yield openid_client_1.Issuer.discover(wellKnownUri);
debug('Metadata retrieval was successfull');
debug('Retrieved issuer: %s and token_endpoint: %s from well_known_uri', issuer.metadata.issuer, issuer.metadata.token_endpoint);
return new issuer.Client(metadata, jwks);
}
catch (error) {
throw new _1.WellKnownURIError(`Error retrieving contents from the well_known_uri: ${config.wellKnownUri}`, error);
}
});
}
}
exports.OpenIDClientFactory = OpenIDClientFactory;