@aws-sdk/middleware-token 3.899.0 → 3.906.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 +52 -85
- package/package.json +7 -7
package/dist-cjs/index.js
CHANGED
|
@@ -1,93 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var protocolHttp = require('@smithy/protocol-http');
|
|
4
|
+
var types = require('@smithy/types');
|
|
5
|
+
var propertyProvider = require('@smithy/property-provider');
|
|
6
|
+
var utilMiddleware = require('@smithy/util-middleware');
|
|
7
|
+
var tokenDefaultProvider = require('./tokenDefaultProvider');
|
|
8
|
+
|
|
9
|
+
const tokenMiddlewareOptions = {
|
|
10
|
+
name: "tokenMiddleware",
|
|
11
|
+
tags: ["TOKEN", "AUTH"],
|
|
12
|
+
relation: "after",
|
|
13
|
+
toMiddleware: "retryMiddleware",
|
|
14
|
+
override: true,
|
|
10
15
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const tokenMiddleware = (options) => (next, context) => async (args) => {
|
|
17
|
+
if (!protocolHttp.HttpRequest.isInstance(args.request) || context.currentAuthConfig)
|
|
18
|
+
return next(args);
|
|
19
|
+
const token = options.token && (await options.token());
|
|
20
|
+
if (token?.token) {
|
|
21
|
+
const authConfig = {
|
|
22
|
+
in: types.HttpAuthLocation.HEADER,
|
|
23
|
+
name: "authorization",
|
|
24
|
+
scheme: "Bearer",
|
|
25
|
+
};
|
|
26
|
+
context.currentAuthConfig = authConfig;
|
|
27
|
+
args.request.headers[authConfig.name] = `${authConfig.scheme} ${token.token}`;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
context.currentAuthConfig = undefined;
|
|
31
|
+
}
|
|
32
|
+
return next(args);
|
|
18
33
|
};
|
|
19
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
34
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
resolveTokenConfig: () => resolveTokenConfig,
|
|
26
|
-
tokenMiddleware: () => tokenMiddleware,
|
|
27
|
-
tokenMiddlewareOptions: () => tokenMiddlewareOptions
|
|
35
|
+
const getTokenPlugin = (options) => ({
|
|
36
|
+
applyToStack: (clientStack) => {
|
|
37
|
+
clientStack.addRelativeTo(tokenMiddleware(options), tokenMiddlewareOptions);
|
|
38
|
+
},
|
|
28
39
|
});
|
|
29
|
-
module.exports = __toCommonJS(index_exports);
|
|
30
40
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
toMiddleware: "retryMiddleware",
|
|
39
|
-
override: true
|
|
41
|
+
const isTokenWithExpiry = (token) => token.expiration !== undefined;
|
|
42
|
+
const isTokenExpiringWithinFiveMins = (token) => isTokenWithExpiry(token) && token.expiration.getTime() - Date.now() < 300000;
|
|
43
|
+
const normalizeTokenProvider = (token) => {
|
|
44
|
+
if (typeof token === "function") {
|
|
45
|
+
return propertyProvider.memoize(token, isTokenExpiringWithinFiveMins, isTokenWithExpiry);
|
|
46
|
+
}
|
|
47
|
+
return utilMiddleware.normalizeProvider(token);
|
|
40
48
|
};
|
|
41
|
-
var tokenMiddleware = /* @__PURE__ */ __name((options) => (next, context) => async (args) => {
|
|
42
|
-
if (!import_protocol_http.HttpRequest.isInstance(args.request) || context.currentAuthConfig) return next(args);
|
|
43
|
-
const token = options.token && await options.token();
|
|
44
|
-
if (token?.token) {
|
|
45
|
-
const authConfig = {
|
|
46
|
-
in: import_types.HttpAuthLocation.HEADER,
|
|
47
|
-
name: "authorization",
|
|
48
|
-
scheme: "Bearer"
|
|
49
|
-
};
|
|
50
|
-
context.currentAuthConfig = authConfig;
|
|
51
|
-
args.request.headers[authConfig.name] = `${authConfig.scheme} ${token.token}`;
|
|
52
|
-
} else {
|
|
53
|
-
context.currentAuthConfig = void 0;
|
|
54
|
-
}
|
|
55
|
-
return next(args);
|
|
56
|
-
}, "tokenMiddleware");
|
|
57
|
-
|
|
58
|
-
// src/getTokenPlugin.ts
|
|
59
|
-
var getTokenPlugin = /* @__PURE__ */ __name((options) => ({
|
|
60
|
-
applyToStack: /* @__PURE__ */ __name((clientStack) => {
|
|
61
|
-
clientStack.addRelativeTo(tokenMiddleware(options), tokenMiddlewareOptions);
|
|
62
|
-
}, "applyToStack")
|
|
63
|
-
}), "getTokenPlugin");
|
|
64
|
-
|
|
65
|
-
// src/normalizeTokenProvider.ts
|
|
66
|
-
var import_property_provider = require("@smithy/property-provider");
|
|
67
|
-
var import_util_middleware = require("@smithy/util-middleware");
|
|
68
|
-
var isTokenWithExpiry = /* @__PURE__ */ __name((token) => token.expiration !== void 0, "isTokenWithExpiry");
|
|
69
|
-
var isTokenExpiringWithinFiveMins = /* @__PURE__ */ __name((token) => isTokenWithExpiry(token) && token.expiration.getTime() - Date.now() < 3e5, "isTokenExpiringWithinFiveMins");
|
|
70
|
-
var normalizeTokenProvider = /* @__PURE__ */ __name((token) => {
|
|
71
|
-
if (typeof token === "function") {
|
|
72
|
-
return (0, import_property_provider.memoize)(token, isTokenExpiringWithinFiveMins, isTokenWithExpiry);
|
|
73
|
-
}
|
|
74
|
-
return (0, import_util_middleware.normalizeProvider)(token);
|
|
75
|
-
}, "normalizeTokenProvider");
|
|
76
49
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
});
|
|
84
|
-
}, "resolveTokenConfig");
|
|
85
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
-
|
|
87
|
-
0 && (module.exports = {
|
|
88
|
-
getTokenPlugin,
|
|
89
|
-
resolveTokenConfig,
|
|
90
|
-
tokenMiddlewareOptions,
|
|
91
|
-
tokenMiddleware
|
|
92
|
-
});
|
|
50
|
+
const resolveTokenConfig = (input) => {
|
|
51
|
+
const { token } = input;
|
|
52
|
+
return Object.assign(input, {
|
|
53
|
+
token: token ? normalizeTokenProvider(token) : tokenDefaultProvider.tokenDefaultProvider(input),
|
|
54
|
+
});
|
|
55
|
+
};
|
|
93
56
|
|
|
57
|
+
exports.getTokenPlugin = getTokenPlugin;
|
|
58
|
+
exports.resolveTokenConfig = resolveTokenConfig;
|
|
59
|
+
exports.tokenMiddleware = tokenMiddleware;
|
|
60
|
+
exports.tokenMiddlewareOptions = tokenMiddlewareOptions;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/middleware-token",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.906.0",
|
|
4
4
|
"description": "Middleware and Plugin for setting token authentication",
|
|
5
5
|
"main": "./dist-cjs/index.js",
|
|
6
6
|
"module": "./dist-es/index.js",
|
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
},
|
|
31
31
|
"license": "Apache-2.0",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@aws-sdk/token-providers": "3.
|
|
34
|
-
"@aws-sdk/types": "3.
|
|
35
|
-
"@smithy/property-provider": "^4.
|
|
36
|
-
"@smithy/protocol-http": "^5.
|
|
37
|
-
"@smithy/types": "^4.
|
|
38
|
-
"@smithy/util-middleware": "^4.
|
|
33
|
+
"@aws-sdk/token-providers": "3.906.0",
|
|
34
|
+
"@aws-sdk/types": "3.901.0",
|
|
35
|
+
"@smithy/property-provider": "^4.2.0",
|
|
36
|
+
"@smithy/protocol-http": "^5.3.0",
|
|
37
|
+
"@smithy/types": "^4.6.0",
|
|
38
|
+
"@smithy/util-middleware": "^4.2.0",
|
|
39
39
|
"tslib": "^2.6.2"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|