"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.httpAuthSchemeMiddleware = void 0; const types_1 = require("@smithy/types"); const util_middleware_1 = require("@smithy/util-middleware"); function convertHttpAuthSchemesToMap(httpAuthSchemes) { const map = new Map(); for (const scheme of httpAuthSchemes) { map.set(scheme.schemeId, scheme); } return map; } const httpAuthSchemeMiddleware = (config, mwOptions) => (next, context) => async (args) => { var _a; const options = config.httpAuthSchemeProvider(await mwOptions.httpAuthSchemeParametersProvider(config, context, args.input)); const authSchemes = convertHttpAuthSchemesToMap(config.httpAuthSchemes); const smithyContext = (0, util_middleware_1.getSmithyContext)(context); const failureReasons = []; for (const option of options) { const scheme = authSchemes.get(option.schemeId); if (!scheme) { failureReasons.push(`HttpAuthScheme \`${option.schemeId}\` was not enabled for this service.`); continue; } const identityProvider = scheme.identityProvider(await mwOptions.identityProviderConfigProvider(config)); if (!identityProvider) { failureReasons.push(`HttpAuthScheme \`${option.schemeId}\` did not have an IdentityProvider configured.`); continue; } const { identityProperties = {}, signingProperties = {} } = ((_a = option.propertiesExtractor) === null || _a === void 0 ? void 0 : _a.call(option, config, context)) || {}; option.identityProperties = Object.assign(option.identityProperties || {}, identityProperties); option.signingProperties = Object.assign(option.signingProperties || {}, signingProperties); smithyContext.selectedHttpAuthScheme = { httpAuthOption: option, identity: await identityProvider(option.identityProperties), signer: scheme.signer, }; break; } if (!smithyContext.selectedHttpAuthScheme) { throw new Error(failureReasons.join("\n")); } return next(args); }; exports.httpAuthSchemeMiddleware = httpAuthSchemeMiddleware;