@smithy/experimental-identity-and-auth 0.4.6 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist-cjs/index.js
CHANGED
|
@@ -1,429 +1,329 @@
|
|
|
1
|
-
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
19
2
|
|
|
20
|
-
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
HttpApiKeyAuthSigner: () => HttpApiKeyAuthSigner,
|
|
27
|
-
HttpBearerAuthSigner: () => HttpBearerAuthSigner,
|
|
28
|
-
NoAuthSigner: () => NoAuthSigner,
|
|
29
|
-
SigV4Signer: () => SigV4Signer,
|
|
30
|
-
createEndpointRuleSetHttpAuthSchemeParametersProvider: () => createEndpointRuleSetHttpAuthSchemeParametersProvider,
|
|
31
|
-
createEndpointRuleSetHttpAuthSchemeProvider: () => createEndpointRuleSetHttpAuthSchemeProvider,
|
|
32
|
-
createIsIdentityExpiredFunction: () => createIsIdentityExpiredFunction,
|
|
33
|
-
doesIdentityRequireRefresh: () => doesIdentityRequireRefresh,
|
|
34
|
-
getHttpAuthSchemeEndpointRuleSetPlugin: () => getHttpAuthSchemeEndpointRuleSetPlugin,
|
|
35
|
-
getHttpAuthSchemePlugin: () => getHttpAuthSchemePlugin,
|
|
36
|
-
getHttpSigningPlugin: () => getHttpSigningPlugin,
|
|
37
|
-
httpAuthSchemeEndpointRuleSetMiddlewareOptions: () => httpAuthSchemeEndpointRuleSetMiddlewareOptions,
|
|
38
|
-
httpAuthSchemeMiddleware: () => httpAuthSchemeMiddleware,
|
|
39
|
-
httpAuthSchemeMiddlewareOptions: () => httpAuthSchemeMiddlewareOptions,
|
|
40
|
-
httpSigningMiddleware: () => httpSigningMiddleware,
|
|
41
|
-
httpSigningMiddlewareOptions: () => httpSigningMiddlewareOptions,
|
|
42
|
-
isIdentityExpired: () => isIdentityExpired,
|
|
43
|
-
memoizeIdentityProvider: () => memoizeIdentityProvider
|
|
44
|
-
});
|
|
45
|
-
module.exports = __toCommonJS(index_exports);
|
|
46
|
-
|
|
47
|
-
// src/IdentityProviderConfig.ts
|
|
48
|
-
var DefaultIdentityProviderConfig = class {
|
|
49
|
-
/**
|
|
50
|
-
* Creates an IdentityProviderConfig with a record of scheme IDs to identity providers.
|
|
51
|
-
*
|
|
52
|
-
* @param config scheme IDs and identity providers to configure
|
|
53
|
-
*/
|
|
54
|
-
constructor(config) {
|
|
55
|
-
this.authSchemes = /* @__PURE__ */ new Map();
|
|
56
|
-
for (const [key, value] of Object.entries(config)) {
|
|
57
|
-
if (value !== void 0) {
|
|
58
|
-
this.authSchemes.set(key, value);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
static {
|
|
63
|
-
__name(this, "DefaultIdentityProviderConfig");
|
|
64
|
-
}
|
|
65
|
-
getIdentityProvider(schemeId) {
|
|
66
|
-
return this.authSchemes.get(schemeId);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
// src/SigV4Signer.ts
|
|
71
|
-
var import_protocol_http = require("@smithy/protocol-http");
|
|
72
|
-
var import_signature_v4 = require("@smithy/signature-v4");
|
|
73
|
-
var SigV4Signer = class {
|
|
74
|
-
static {
|
|
75
|
-
__name(this, "SigV4Signer");
|
|
76
|
-
}
|
|
77
|
-
async sign(httpRequest, identity, signingProperties) {
|
|
78
|
-
const clonedRequest = import_protocol_http.HttpRequest.clone(httpRequest);
|
|
79
|
-
const signer = new import_signature_v4.SignatureV4({
|
|
80
|
-
applyChecksum: signingProperties.applyChecksum !== void 0 ? signingProperties.applyChecksum : true,
|
|
81
|
-
credentials: identity,
|
|
82
|
-
region: signingProperties.region,
|
|
83
|
-
service: signingProperties.name,
|
|
84
|
-
sha256: signingProperties.sha256,
|
|
85
|
-
uriEscapePath: signingProperties.uriEscapePath !== void 0 ? signingProperties.uriEscapePath : true
|
|
86
|
-
});
|
|
87
|
-
return signer.sign(clonedRequest, {
|
|
88
|
-
signingDate: /* @__PURE__ */ new Date(),
|
|
89
|
-
signableHeaders: signingProperties.signableHeaders,
|
|
90
|
-
unsignableHeaders: signingProperties.unsignableHeaders,
|
|
91
|
-
signingRegion: signingProperties.signingRegion,
|
|
92
|
-
signingService: signingProperties.signingService
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
};
|
|
3
|
+
var protocolHttp = require('@smithy/protocol-http');
|
|
4
|
+
var signatureV4 = require('@smithy/signature-v4');
|
|
5
|
+
var middlewareEndpoint = require('@smithy/middleware-endpoint');
|
|
6
|
+
var utilMiddleware = require('@smithy/util-middleware');
|
|
7
|
+
var middlewareSerde = require('@smithy/middleware-serde');
|
|
8
|
+
var middlewareRetry = require('@smithy/middleware-retry');
|
|
96
9
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (!authSchemes) {
|
|
105
|
-
return defaultHttpAuthSchemeResolver(authParameters);
|
|
106
|
-
}
|
|
107
|
-
const options = [];
|
|
108
|
-
for (const scheme of authSchemes) {
|
|
109
|
-
const { name: resolvedName, properties = {}, ...rest } = scheme;
|
|
110
|
-
const name = resolvedName.toLowerCase();
|
|
111
|
-
if (resolvedName !== name) {
|
|
112
|
-
console.warn(`HttpAuthScheme has been normalized with lowercasing: \`${resolvedName}\` to \`${name}\``);
|
|
113
|
-
}
|
|
114
|
-
let schemeId;
|
|
115
|
-
if (name === "sigv4") {
|
|
116
|
-
schemeId = "aws.auth#sigv4";
|
|
117
|
-
} else if (name === "sigv4a") {
|
|
118
|
-
schemeId = "aws.auth#sigv4a";
|
|
119
|
-
} else {
|
|
120
|
-
throw new Error(`Unknown HttpAuthScheme found in \`@smithy.rules#endpointRuleSet\`: \`${name}\``);
|
|
121
|
-
}
|
|
122
|
-
options.push({
|
|
123
|
-
schemeId,
|
|
124
|
-
signingProperties: {
|
|
125
|
-
...rest,
|
|
126
|
-
...properties
|
|
10
|
+
class DefaultIdentityProviderConfig {
|
|
11
|
+
authSchemes = new Map();
|
|
12
|
+
constructor(config) {
|
|
13
|
+
for (const [key, value] of Object.entries(config)) {
|
|
14
|
+
if (value !== undefined) {
|
|
15
|
+
this.authSchemes.set(key, value);
|
|
16
|
+
}
|
|
127
17
|
}
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
return options;
|
|
131
|
-
}, "endpointRuleSetHttpAuthSchemeProvider");
|
|
132
|
-
return endpointRuleSetHttpAuthSchemeProvider;
|
|
133
|
-
}, "createEndpointRuleSetHttpAuthSchemeProvider");
|
|
134
|
-
var createEndpointRuleSetHttpAuthSchemeParametersProvider = /* @__PURE__ */ __name((defaultHttpAuthSchemeParametersProvider) => async (config, context, input) => {
|
|
135
|
-
if (!input) {
|
|
136
|
-
throw new Error(`Could not find \`input\` for \`defaultEndpointRuleSetHttpAuthSchemeParametersProvider\``);
|
|
137
|
-
}
|
|
138
|
-
const defaultParameters = await defaultHttpAuthSchemeParametersProvider(config, context, input);
|
|
139
|
-
const instructionsFn = (0, import_util_middleware.getSmithyContext)(context)?.endpointRuleSet?.getEndpointParameterInstructions;
|
|
140
|
-
if (!instructionsFn) {
|
|
141
|
-
throw new Error(`getEndpointParameterInstructions() is not defined on \`${context.commandName}\``);
|
|
142
|
-
}
|
|
143
|
-
const endpointParameters = await (0, import_middleware_endpoint.resolveParams)(
|
|
144
|
-
input,
|
|
145
|
-
{ getEndpointParameterInstructions: instructionsFn },
|
|
146
|
-
config
|
|
147
|
-
);
|
|
148
|
-
return Object.assign(defaultParameters, endpointParameters);
|
|
149
|
-
}, "createEndpointRuleSetHttpAuthSchemeParametersProvider");
|
|
150
|
-
|
|
151
|
-
// src/httpApiKeyAuth.ts
|
|
152
|
-
|
|
153
|
-
var HttpApiKeyAuthLocation = /* @__PURE__ */ ((HttpApiKeyAuthLocation2) => {
|
|
154
|
-
HttpApiKeyAuthLocation2["HEADER"] = "header";
|
|
155
|
-
HttpApiKeyAuthLocation2["QUERY"] = "query";
|
|
156
|
-
return HttpApiKeyAuthLocation2;
|
|
157
|
-
})(HttpApiKeyAuthLocation || {});
|
|
158
|
-
var HttpApiKeyAuthSigner = class {
|
|
159
|
-
static {
|
|
160
|
-
__name(this, "HttpApiKeyAuthSigner");
|
|
161
|
-
}
|
|
162
|
-
async sign(httpRequest, identity, signingProperties) {
|
|
163
|
-
if (!signingProperties) {
|
|
164
|
-
throw new Error(
|
|
165
|
-
"request could not be signed with `apiKey` since the `name` and `in` signer properties are missing"
|
|
166
|
-
);
|
|
167
18
|
}
|
|
168
|
-
|
|
169
|
-
|
|
19
|
+
getIdentityProvider(schemeId) {
|
|
20
|
+
return this.authSchemes.get(schemeId);
|
|
170
21
|
}
|
|
171
|
-
|
|
172
|
-
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
class SigV4Signer {
|
|
25
|
+
async sign(httpRequest, identity, signingProperties) {
|
|
26
|
+
const clonedRequest = protocolHttp.HttpRequest.clone(httpRequest);
|
|
27
|
+
const signer = new signatureV4.SignatureV4({
|
|
28
|
+
applyChecksum: signingProperties.applyChecksum !== undefined ? signingProperties.applyChecksum : true,
|
|
29
|
+
credentials: identity,
|
|
30
|
+
region: signingProperties.region,
|
|
31
|
+
service: signingProperties.name,
|
|
32
|
+
sha256: signingProperties.sha256,
|
|
33
|
+
uriEscapePath: signingProperties.uriEscapePath !== undefined ? signingProperties.uriEscapePath : true,
|
|
34
|
+
});
|
|
35
|
+
return signer.sign(clonedRequest, {
|
|
36
|
+
signingDate: new Date(),
|
|
37
|
+
signableHeaders: signingProperties.signableHeaders,
|
|
38
|
+
unsignableHeaders: signingProperties.unsignableHeaders,
|
|
39
|
+
signingRegion: signingProperties.signingRegion,
|
|
40
|
+
signingService: signingProperties.signingService,
|
|
41
|
+
});
|
|
173
42
|
}
|
|
174
|
-
|
|
175
|
-
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const createEndpointRuleSetHttpAuthSchemeProvider = (defaultEndpointResolver, defaultHttpAuthSchemeResolver) => {
|
|
46
|
+
const endpointRuleSetHttpAuthSchemeProvider = (authParameters) => {
|
|
47
|
+
const endpoint = defaultEndpointResolver(authParameters);
|
|
48
|
+
const authSchemes = endpoint.properties?.authSchemes;
|
|
49
|
+
if (!authSchemes) {
|
|
50
|
+
return defaultHttpAuthSchemeResolver(authParameters);
|
|
51
|
+
}
|
|
52
|
+
const options = [];
|
|
53
|
+
for (const scheme of authSchemes) {
|
|
54
|
+
const { name: resolvedName, properties = {}, ...rest } = scheme;
|
|
55
|
+
const name = resolvedName.toLowerCase();
|
|
56
|
+
if (resolvedName !== name) {
|
|
57
|
+
console.warn(`HttpAuthScheme has been normalized with lowercasing: \`${resolvedName}\` to \`${name}\``);
|
|
58
|
+
}
|
|
59
|
+
let schemeId;
|
|
60
|
+
if (name === "sigv4") {
|
|
61
|
+
schemeId = "aws.auth#sigv4";
|
|
62
|
+
}
|
|
63
|
+
else if (name === "sigv4a") {
|
|
64
|
+
schemeId = "aws.auth#sigv4a";
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
throw new Error(`Unknown HttpAuthScheme found in \`@smithy.rules#endpointRuleSet\`: \`${name}\``);
|
|
68
|
+
}
|
|
69
|
+
options.push({
|
|
70
|
+
schemeId,
|
|
71
|
+
signingProperties: {
|
|
72
|
+
...rest,
|
|
73
|
+
...properties,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return options;
|
|
78
|
+
};
|
|
79
|
+
return endpointRuleSetHttpAuthSchemeProvider;
|
|
80
|
+
};
|
|
81
|
+
const createEndpointRuleSetHttpAuthSchemeParametersProvider = (defaultHttpAuthSchemeParametersProvider) => async (config, context, input) => {
|
|
82
|
+
if (!input) {
|
|
83
|
+
throw new Error(`Could not find \`input\` for \`defaultEndpointRuleSetHttpAuthSchemeParametersProvider\``);
|
|
176
84
|
}
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
} else {
|
|
183
|
-
throw new Error(
|
|
184
|
-
"request can only be signed with `apiKey` locations `query` or `header`, but found: `" + signingProperties.in + "`"
|
|
185
|
-
);
|
|
85
|
+
const defaultParameters = await defaultHttpAuthSchemeParametersProvider(config, context, input);
|
|
86
|
+
const instructionsFn = utilMiddleware.getSmithyContext(context)?.endpointRuleSet
|
|
87
|
+
?.getEndpointParameterInstructions;
|
|
88
|
+
if (!instructionsFn) {
|
|
89
|
+
throw new Error(`getEndpointParameterInstructions() is not defined on \`${context.commandName}\``);
|
|
186
90
|
}
|
|
187
|
-
|
|
188
|
-
|
|
91
|
+
const endpointParameters = await middlewareEndpoint.resolveParams(input, { getEndpointParameterInstructions: instructionsFn }, config);
|
|
92
|
+
return Object.assign(defaultParameters, endpointParameters);
|
|
189
93
|
};
|
|
190
94
|
|
|
191
|
-
|
|
95
|
+
exports.HttpApiKeyAuthLocation = void 0;
|
|
96
|
+
(function (HttpApiKeyAuthLocation) {
|
|
97
|
+
HttpApiKeyAuthLocation["HEADER"] = "header";
|
|
98
|
+
HttpApiKeyAuthLocation["QUERY"] = "query";
|
|
99
|
+
})(exports.HttpApiKeyAuthLocation || (exports.HttpApiKeyAuthLocation = {}));
|
|
100
|
+
class HttpApiKeyAuthSigner {
|
|
101
|
+
async sign(httpRequest, identity, signingProperties) {
|
|
102
|
+
if (!signingProperties) {
|
|
103
|
+
throw new Error("request could not be signed with `apiKey` since the `name` and `in` signer properties are missing");
|
|
104
|
+
}
|
|
105
|
+
if (!signingProperties.name) {
|
|
106
|
+
throw new Error("request could not be signed with `apiKey` since the `name` signer property is missing");
|
|
107
|
+
}
|
|
108
|
+
if (!signingProperties.in) {
|
|
109
|
+
throw new Error("request could not be signed with `apiKey` since the `in` signer property is missing");
|
|
110
|
+
}
|
|
111
|
+
if (!identity.apiKey) {
|
|
112
|
+
throw new Error("request could not be signed with `apiKey` since the `apiKey` is not defined");
|
|
113
|
+
}
|
|
114
|
+
const clonedRequest = protocolHttp.HttpRequest.clone(httpRequest);
|
|
115
|
+
if (signingProperties.in === exports.HttpApiKeyAuthLocation.QUERY) {
|
|
116
|
+
clonedRequest.query[signingProperties.name] = identity.apiKey;
|
|
117
|
+
}
|
|
118
|
+
else if (signingProperties.in === exports.HttpApiKeyAuthLocation.HEADER) {
|
|
119
|
+
clonedRequest.headers[signingProperties.name] = signingProperties.scheme
|
|
120
|
+
? `${signingProperties.scheme} ${identity.apiKey}`
|
|
121
|
+
: identity.apiKey;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
throw new Error("request can only be signed with `apiKey` locations `query` or `header`, " +
|
|
125
|
+
"but found: `" +
|
|
126
|
+
signingProperties.in +
|
|
127
|
+
"`");
|
|
128
|
+
}
|
|
129
|
+
return clonedRequest;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
192
132
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
133
|
+
class HttpBearerAuthSigner {
|
|
134
|
+
async sign(httpRequest, identity, signingProperties) {
|
|
135
|
+
const clonedRequest = protocolHttp.HttpRequest.clone(httpRequest);
|
|
136
|
+
if (!identity.token) {
|
|
137
|
+
throw new Error("request could not be signed with `token` since the `token` is not defined");
|
|
138
|
+
}
|
|
139
|
+
clonedRequest.headers["Authorization"] = `Bearer ${identity.token}`;
|
|
140
|
+
return clonedRequest;
|
|
201
141
|
}
|
|
202
|
-
|
|
203
|
-
return clonedRequest;
|
|
204
|
-
}
|
|
205
|
-
};
|
|
142
|
+
}
|
|
206
143
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
const normalizedProvider = typeof provider !== "function" ? async () => Promise.resolve(provider) : provider;
|
|
217
|
-
let resolved;
|
|
218
|
-
let pending;
|
|
219
|
-
let hasResult;
|
|
220
|
-
let isConstant = false;
|
|
221
|
-
const coalesceProvider = /* @__PURE__ */ __name(async (options) => {
|
|
222
|
-
if (!pending) {
|
|
223
|
-
pending = normalizedProvider(options);
|
|
144
|
+
const createIsIdentityExpiredFunction = (expirationMs) => function isIdentityExpired(identity) {
|
|
145
|
+
return doesIdentityRequireRefresh(identity) && identity.expiration.getTime() - Date.now() < expirationMs;
|
|
146
|
+
};
|
|
147
|
+
const EXPIRATION_MS = 300_000;
|
|
148
|
+
const isIdentityExpired = createIsIdentityExpiredFunction(EXPIRATION_MS);
|
|
149
|
+
const doesIdentityRequireRefresh = (identity) => identity.expiration !== undefined;
|
|
150
|
+
const memoizeIdentityProvider = (provider, isExpired, requiresRefresh) => {
|
|
151
|
+
if (provider === undefined) {
|
|
152
|
+
return undefined;
|
|
224
153
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
154
|
+
const normalizedProvider = typeof provider !== "function" ? async () => Promise.resolve(provider) : provider;
|
|
155
|
+
let resolved;
|
|
156
|
+
let pending;
|
|
157
|
+
let hasResult;
|
|
158
|
+
let isConstant = false;
|
|
159
|
+
const coalesceProvider = async (options) => {
|
|
160
|
+
if (!pending) {
|
|
161
|
+
pending = normalizedProvider(options);
|
|
162
|
+
}
|
|
163
|
+
try {
|
|
164
|
+
resolved = await pending;
|
|
165
|
+
hasResult = true;
|
|
166
|
+
isConstant = false;
|
|
167
|
+
}
|
|
168
|
+
finally {
|
|
169
|
+
pending = undefined;
|
|
170
|
+
}
|
|
171
|
+
return resolved;
|
|
172
|
+
};
|
|
173
|
+
if (isExpired === undefined) {
|
|
174
|
+
return async (options) => {
|
|
175
|
+
if (!hasResult || options?.forceRefresh) {
|
|
176
|
+
resolved = await coalesceProvider(options);
|
|
177
|
+
}
|
|
178
|
+
return resolved;
|
|
179
|
+
};
|
|
231
180
|
}
|
|
232
|
-
return resolved;
|
|
233
|
-
}, "coalesceProvider");
|
|
234
|
-
if (isExpired === void 0) {
|
|
235
181
|
return async (options) => {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
182
|
+
if (!hasResult || options?.forceRefresh) {
|
|
183
|
+
resolved = await coalesceProvider(options);
|
|
184
|
+
}
|
|
185
|
+
if (isConstant) {
|
|
186
|
+
return resolved;
|
|
187
|
+
}
|
|
188
|
+
if (!requiresRefresh(resolved)) {
|
|
189
|
+
isConstant = true;
|
|
190
|
+
return resolved;
|
|
191
|
+
}
|
|
192
|
+
if (isExpired(resolved)) {
|
|
193
|
+
await coalesceProvider(options);
|
|
194
|
+
return resolved;
|
|
195
|
+
}
|
|
196
|
+
return resolved;
|
|
240
197
|
};
|
|
241
|
-
|
|
242
|
-
return async (options) => {
|
|
243
|
-
if (!hasResult || options?.forceRefresh) {
|
|
244
|
-
resolved = await coalesceProvider(options);
|
|
245
|
-
}
|
|
246
|
-
if (isConstant) {
|
|
247
|
-
return resolved;
|
|
248
|
-
}
|
|
249
|
-
if (!requiresRefresh(resolved)) {
|
|
250
|
-
isConstant = true;
|
|
251
|
-
return resolved;
|
|
252
|
-
}
|
|
253
|
-
if (isExpired(resolved)) {
|
|
254
|
-
await coalesceProvider(options);
|
|
255
|
-
return resolved;
|
|
256
|
-
}
|
|
257
|
-
return resolved;
|
|
258
|
-
};
|
|
259
|
-
}, "memoizeIdentityProvider");
|
|
260
|
-
|
|
261
|
-
// src/middleware-http-auth-scheme/httpAuthSchemeMiddleware.ts
|
|
198
|
+
};
|
|
262
199
|
|
|
263
200
|
function convertHttpAuthSchemesToMap(httpAuthSchemes) {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
201
|
+
const map = new Map();
|
|
202
|
+
for (const scheme of httpAuthSchemes) {
|
|
203
|
+
map.set(scheme.schemeId, scheme);
|
|
204
|
+
}
|
|
205
|
+
return map;
|
|
269
206
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
207
|
+
const httpAuthSchemeMiddleware = (config, mwOptions) => (next, context) => async (args) => {
|
|
208
|
+
const options = config.httpAuthSchemeProvider(await mwOptions.httpAuthSchemeParametersProvider(config, context, args.input));
|
|
209
|
+
const authSchemes = convertHttpAuthSchemesToMap(config.httpAuthSchemes);
|
|
210
|
+
const smithyContext = utilMiddleware.getSmithyContext(context);
|
|
211
|
+
const failureReasons = [];
|
|
212
|
+
for (const option of options) {
|
|
213
|
+
const scheme = authSchemes.get(option.schemeId);
|
|
214
|
+
if (!scheme) {
|
|
215
|
+
failureReasons.push(`HttpAuthScheme \`${option.schemeId}\` was not enabled for this service.`);
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
const identityProvider = scheme.identityProvider(await mwOptions.identityProviderConfigProvider(config));
|
|
219
|
+
if (!identityProvider) {
|
|
220
|
+
failureReasons.push(`HttpAuthScheme \`${option.schemeId}\` did not have an IdentityProvider configured.`);
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
const { identityProperties = {}, signingProperties = {} } = option.propertiesExtractor?.(config, context) || {};
|
|
224
|
+
option.identityProperties = Object.assign(option.identityProperties || {}, identityProperties);
|
|
225
|
+
option.signingProperties = Object.assign(option.signingProperties || {}, signingProperties);
|
|
226
|
+
smithyContext.selectedHttpAuthScheme = {
|
|
227
|
+
httpAuthOption: option,
|
|
228
|
+
identity: await identityProvider(option.identityProperties),
|
|
229
|
+
signer: scheme.signer,
|
|
230
|
+
};
|
|
231
|
+
break;
|
|
283
232
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
failureReasons.push(`HttpAuthScheme \`${option.schemeId}\` did not have an IdentityProvider configured.`);
|
|
287
|
-
continue;
|
|
233
|
+
if (!smithyContext.selectedHttpAuthScheme) {
|
|
234
|
+
throw new Error(failureReasons.join("\n"));
|
|
288
235
|
}
|
|
289
|
-
|
|
290
|
-
option.identityProperties = Object.assign(option.identityProperties || {}, identityProperties);
|
|
291
|
-
option.signingProperties = Object.assign(option.signingProperties || {}, signingProperties);
|
|
292
|
-
smithyContext.selectedHttpAuthScheme = {
|
|
293
|
-
httpAuthOption: option,
|
|
294
|
-
identity: await identityProvider(option.identityProperties),
|
|
295
|
-
signer: scheme.signer
|
|
296
|
-
};
|
|
297
|
-
break;
|
|
298
|
-
}
|
|
299
|
-
if (!smithyContext.selectedHttpAuthScheme) {
|
|
300
|
-
throw new Error(failureReasons.join("\n"));
|
|
301
|
-
}
|
|
302
|
-
return next(args);
|
|
303
|
-
}, "httpAuthSchemeMiddleware");
|
|
304
|
-
|
|
305
|
-
// src/middleware-http-auth-scheme/getHttpAuthSchemeEndpointRuleSetPlugin.ts
|
|
306
|
-
|
|
307
|
-
var httpAuthSchemeEndpointRuleSetMiddlewareOptions = {
|
|
308
|
-
step: "serialize",
|
|
309
|
-
tags: ["HTTP_AUTH_SCHEME"],
|
|
310
|
-
name: "httpAuthSchemeMiddleware",
|
|
311
|
-
override: true,
|
|
312
|
-
relation: "before",
|
|
313
|
-
toMiddleware: import_middleware_endpoint.endpointMiddlewareOptions.name
|
|
236
|
+
return next(args);
|
|
314
237
|
};
|
|
315
|
-
var getHttpAuthSchemeEndpointRuleSetPlugin = /* @__PURE__ */ __name((config, {
|
|
316
|
-
httpAuthSchemeParametersProvider,
|
|
317
|
-
identityProviderConfigProvider
|
|
318
|
-
}) => ({
|
|
319
|
-
applyToStack: /* @__PURE__ */ __name((clientStack) => {
|
|
320
|
-
clientStack.addRelativeTo(
|
|
321
|
-
httpAuthSchemeMiddleware(config, {
|
|
322
|
-
httpAuthSchemeParametersProvider,
|
|
323
|
-
identityProviderConfigProvider
|
|
324
|
-
}),
|
|
325
|
-
httpAuthSchemeEndpointRuleSetMiddlewareOptions
|
|
326
|
-
);
|
|
327
|
-
}, "applyToStack")
|
|
328
|
-
}), "getHttpAuthSchemeEndpointRuleSetPlugin");
|
|
329
238
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
relation: "before",
|
|
338
|
-
toMiddleware: import_middleware_serde.serializerMiddlewareOption.name
|
|
239
|
+
const httpAuthSchemeEndpointRuleSetMiddlewareOptions = {
|
|
240
|
+
step: "serialize",
|
|
241
|
+
tags: ["HTTP_AUTH_SCHEME"],
|
|
242
|
+
name: "httpAuthSchemeMiddleware",
|
|
243
|
+
override: true,
|
|
244
|
+
relation: "before",
|
|
245
|
+
toMiddleware: middlewareEndpoint.endpointMiddlewareOptions.name,
|
|
339
246
|
};
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
identityProviderConfigProvider
|
|
349
|
-
}),
|
|
350
|
-
httpAuthSchemeMiddlewareOptions
|
|
351
|
-
);
|
|
352
|
-
}, "applyToStack")
|
|
353
|
-
}), "getHttpAuthSchemePlugin");
|
|
354
|
-
|
|
355
|
-
// src/middleware-http-signing/httpSigningMiddleware.ts
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
var httpSigningMiddleware = /* @__PURE__ */ __name((config) => (next, context) => async (args) => {
|
|
359
|
-
if (!import_protocol_http.HttpRequest.isInstance(args.request)) {
|
|
360
|
-
return next(args);
|
|
361
|
-
}
|
|
362
|
-
const smithyContext = (0, import_util_middleware.getSmithyContext)(context);
|
|
363
|
-
const scheme = smithyContext.selectedHttpAuthScheme;
|
|
364
|
-
if (!scheme) {
|
|
365
|
-
throw new Error(`No HttpAuthScheme was selected: unable to sign request`);
|
|
366
|
-
}
|
|
367
|
-
const {
|
|
368
|
-
httpAuthOption: { signingProperties },
|
|
369
|
-
identity,
|
|
370
|
-
signer
|
|
371
|
-
} = scheme;
|
|
372
|
-
return next({
|
|
373
|
-
...args,
|
|
374
|
-
request: await signer.sign(args.request, identity, signingProperties || {})
|
|
375
|
-
});
|
|
376
|
-
}, "httpSigningMiddleware");
|
|
247
|
+
const getHttpAuthSchemeEndpointRuleSetPlugin = (config, { httpAuthSchemeParametersProvider, identityProviderConfigProvider, }) => ({
|
|
248
|
+
applyToStack: (clientStack) => {
|
|
249
|
+
clientStack.addRelativeTo(httpAuthSchemeMiddleware(config, {
|
|
250
|
+
httpAuthSchemeParametersProvider,
|
|
251
|
+
identityProviderConfigProvider,
|
|
252
|
+
}), httpAuthSchemeEndpointRuleSetMiddlewareOptions);
|
|
253
|
+
},
|
|
254
|
+
});
|
|
377
255
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
override: true,
|
|
386
|
-
relation: "after",
|
|
387
|
-
toMiddleware: import_middleware_retry.retryMiddlewareOptions.name
|
|
256
|
+
const httpAuthSchemeMiddlewareOptions = {
|
|
257
|
+
step: "serialize",
|
|
258
|
+
tags: ["HTTP_AUTH_SCHEME"],
|
|
259
|
+
name: "httpAuthSchemeMiddleware",
|
|
260
|
+
override: true,
|
|
261
|
+
relation: "before",
|
|
262
|
+
toMiddleware: middlewareSerde.serializerMiddlewareOption.name,
|
|
388
263
|
};
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
264
|
+
const getHttpAuthSchemePlugin = (config, { httpAuthSchemeParametersProvider, identityProviderConfigProvider, }) => ({
|
|
265
|
+
applyToStack: (clientStack) => {
|
|
266
|
+
clientStack.addRelativeTo(httpAuthSchemeMiddleware(config, {
|
|
267
|
+
httpAuthSchemeParametersProvider,
|
|
268
|
+
identityProviderConfigProvider,
|
|
269
|
+
}), httpAuthSchemeMiddlewareOptions);
|
|
270
|
+
},
|
|
271
|
+
});
|
|
394
272
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
273
|
+
const httpSigningMiddleware = (config) => (next, context) => async (args) => {
|
|
274
|
+
if (!protocolHttp.HttpRequest.isInstance(args.request)) {
|
|
275
|
+
return next(args);
|
|
276
|
+
}
|
|
277
|
+
const smithyContext = utilMiddleware.getSmithyContext(context);
|
|
278
|
+
const scheme = smithyContext.selectedHttpAuthScheme;
|
|
279
|
+
if (!scheme) {
|
|
280
|
+
throw new Error(`No HttpAuthScheme was selected: unable to sign request`);
|
|
281
|
+
}
|
|
282
|
+
const { httpAuthOption: { signingProperties }, identity, signer, } = scheme;
|
|
283
|
+
return next({
|
|
284
|
+
...args,
|
|
285
|
+
request: await signer.sign(args.request, identity, signingProperties || {}),
|
|
286
|
+
});
|
|
403
287
|
};
|
|
404
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
405
288
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
httpAuthSchemeMiddleware,
|
|
420
|
-
httpAuthSchemeEndpointRuleSetMiddlewareOptions,
|
|
421
|
-
getHttpAuthSchemeEndpointRuleSetPlugin,
|
|
422
|
-
httpAuthSchemeMiddlewareOptions,
|
|
423
|
-
getHttpAuthSchemePlugin,
|
|
424
|
-
httpSigningMiddleware,
|
|
425
|
-
httpSigningMiddlewareOptions,
|
|
426
|
-
getHttpSigningPlugin,
|
|
427
|
-
NoAuthSigner
|
|
289
|
+
const httpSigningMiddlewareOptions = {
|
|
290
|
+
step: "finalizeRequest",
|
|
291
|
+
tags: ["HTTP_SIGNING"],
|
|
292
|
+
name: "httpSigningMiddleware",
|
|
293
|
+
aliases: ["apiKeyMiddleware", "tokenMiddleware", "awsAuthMiddleware"],
|
|
294
|
+
override: true,
|
|
295
|
+
relation: "after",
|
|
296
|
+
toMiddleware: middlewareRetry.retryMiddlewareOptions.name,
|
|
297
|
+
};
|
|
298
|
+
const getHttpSigningPlugin = (config) => ({
|
|
299
|
+
applyToStack: (clientStack) => {
|
|
300
|
+
clientStack.addRelativeTo(httpSigningMiddleware(), httpSigningMiddlewareOptions);
|
|
301
|
+
},
|
|
428
302
|
});
|
|
429
303
|
|
|
304
|
+
class NoAuthSigner {
|
|
305
|
+
async sign(httpRequest, identity, signingProperties) {
|
|
306
|
+
return httpRequest;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
exports.DefaultIdentityProviderConfig = DefaultIdentityProviderConfig;
|
|
311
|
+
exports.EXPIRATION_MS = EXPIRATION_MS;
|
|
312
|
+
exports.HttpApiKeyAuthSigner = HttpApiKeyAuthSigner;
|
|
313
|
+
exports.HttpBearerAuthSigner = HttpBearerAuthSigner;
|
|
314
|
+
exports.NoAuthSigner = NoAuthSigner;
|
|
315
|
+
exports.SigV4Signer = SigV4Signer;
|
|
316
|
+
exports.createEndpointRuleSetHttpAuthSchemeParametersProvider = createEndpointRuleSetHttpAuthSchemeParametersProvider;
|
|
317
|
+
exports.createEndpointRuleSetHttpAuthSchemeProvider = createEndpointRuleSetHttpAuthSchemeProvider;
|
|
318
|
+
exports.createIsIdentityExpiredFunction = createIsIdentityExpiredFunction;
|
|
319
|
+
exports.doesIdentityRequireRefresh = doesIdentityRequireRefresh;
|
|
320
|
+
exports.getHttpAuthSchemeEndpointRuleSetPlugin = getHttpAuthSchemeEndpointRuleSetPlugin;
|
|
321
|
+
exports.getHttpAuthSchemePlugin = getHttpAuthSchemePlugin;
|
|
322
|
+
exports.getHttpSigningPlugin = getHttpSigningPlugin;
|
|
323
|
+
exports.httpAuthSchemeEndpointRuleSetMiddlewareOptions = httpAuthSchemeEndpointRuleSetMiddlewareOptions;
|
|
324
|
+
exports.httpAuthSchemeMiddleware = httpAuthSchemeMiddleware;
|
|
325
|
+
exports.httpAuthSchemeMiddlewareOptions = httpAuthSchemeMiddlewareOptions;
|
|
326
|
+
exports.httpSigningMiddleware = httpSigningMiddleware;
|
|
327
|
+
exports.httpSigningMiddlewareOptions = httpSigningMiddlewareOptions;
|
|
328
|
+
exports.isIdentityExpired = isIdentityExpired;
|
|
329
|
+
exports.memoizeIdentityProvider = memoizeIdentityProvider;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export const createIsIdentityExpiredFunction = (expirationMs) =>
|
|
2
|
-
|
|
1
|
+
export const createIsIdentityExpiredFunction = (expirationMs) => function isIdentityExpired(identity) {
|
|
2
|
+
return doesIdentityRequireRefresh(identity) && identity.expiration.getTime() - Date.now() < expirationMs;
|
|
3
|
+
};
|
|
4
|
+
export const EXPIRATION_MS = 300_000;
|
|
3
5
|
export const isIdentityExpired = createIsIdentityExpiredFunction(EXPIRATION_MS);
|
|
4
6
|
export const doesIdentityRequireRefresh = (identity) => identity.expiration !== undefined;
|
|
5
7
|
export const memoizeIdentityProvider = (provider, isExpired, requiresRefresh) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smithy/experimental-identity-and-auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
|
|
6
6
|
"build:cjs": "node ../../scripts/inline experimental-identity-and-auth",
|
|
@@ -27,13 +27,13 @@
|
|
|
27
27
|
"license": "Apache-2.0",
|
|
28
28
|
"sideEffects": false,
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@smithy/middleware-endpoint": "^4.
|
|
31
|
-
"@smithy/middleware-retry": "^4.
|
|
32
|
-
"@smithy/middleware-serde": "^4.
|
|
33
|
-
"@smithy/protocol-http": "^5.
|
|
34
|
-
"@smithy/signature-v4": "^5.
|
|
35
|
-
"@smithy/types": "^4.
|
|
36
|
-
"@smithy/util-middleware": "^4.
|
|
30
|
+
"@smithy/middleware-endpoint": "^4.3.0",
|
|
31
|
+
"@smithy/middleware-retry": "^4.4.0",
|
|
32
|
+
"@smithy/middleware-serde": "^4.2.0",
|
|
33
|
+
"@smithy/protocol-http": "^5.3.0",
|
|
34
|
+
"@smithy/signature-v4": "^5.3.0",
|
|
35
|
+
"@smithy/types": "^4.6.0",
|
|
36
|
+
"@smithy/util-middleware": "^4.2.0",
|
|
37
37
|
"tslib": "^2.6.2"
|
|
38
38
|
},
|
|
39
39
|
"engines": {
|