@aws-sdk/token-providers 3.1068.0 → 3.1070.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 +26 -28
- package/package.json +7 -7
package/dist-cjs/index.js
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var config = require('@smithy/core/config');
|
|
6
|
-
var node_fs = require('node:fs');
|
|
1
|
+
const { setTokenFeature } = require("@aws-sdk/core/client");
|
|
2
|
+
const { getBearerTokenEnvKey } = require("@aws-sdk/core/httpAuthSchemes");
|
|
3
|
+
const { TokenProviderError, getSSOTokenFilepath, parseKnownFiles, getProfileName, loadSsoSessionData, getSSOTokenFromFile, memoize, chain } = require("@smithy/core/config");
|
|
4
|
+
const { promises } = require("node:fs");
|
|
7
5
|
|
|
8
6
|
const fromEnvSigningName = ({ logger, signingName } = {}) => async () => {
|
|
9
7
|
logger?.debug?.("@aws-sdk/token-providers - fromEnvSigningName");
|
|
10
8
|
if (!signingName) {
|
|
11
|
-
throw new
|
|
9
|
+
throw new TokenProviderError("Please pass 'signingName' to compute environment variable key", { logger });
|
|
12
10
|
}
|
|
13
|
-
const bearerTokenKey =
|
|
11
|
+
const bearerTokenKey = getBearerTokenEnvKey(signingName);
|
|
14
12
|
if (!(bearerTokenKey in process.env)) {
|
|
15
|
-
throw new
|
|
13
|
+
throw new TokenProviderError(`Token not present in '${bearerTokenKey}' environment variable`, { logger });
|
|
16
14
|
}
|
|
17
15
|
const token = { token: process.env[bearerTokenKey] };
|
|
18
|
-
|
|
16
|
+
setTokenFeature(token, "BEARER_SERVICE_ENV_VARS", "3");
|
|
19
17
|
return token;
|
|
20
18
|
};
|
|
21
19
|
|
|
@@ -23,7 +21,7 @@ const EXPIRE_WINDOW_MS = 5 * 60 * 1000;
|
|
|
23
21
|
const REFRESH_MESSAGE = `To refresh this SSO session run 'aws sso login' with the corresponding profile.`;
|
|
24
22
|
|
|
25
23
|
const getSsoOidcClient = async (ssoRegion, init = {}, callerClientConfig) => {
|
|
26
|
-
const { SSOOIDCClient } =
|
|
24
|
+
const { SSOOIDCClient } = require('@aws-sdk/nested-clients/sso-oidc');
|
|
27
25
|
const coalesce = (prop) => init.clientConfig?.[prop] ?? init.parentClientConfig?.[prop] ?? callerClientConfig?.[prop];
|
|
28
26
|
const ssoOidcClient = new SSOOIDCClient(Object.assign({}, init.clientConfig ?? {}, {
|
|
29
27
|
region: ssoRegion ?? init.clientConfig?.region,
|
|
@@ -34,7 +32,7 @@ const getSsoOidcClient = async (ssoRegion, init = {}, callerClientConfig) => {
|
|
|
34
32
|
};
|
|
35
33
|
|
|
36
34
|
const getNewSsoOidcToken = async (ssoToken, ssoRegion, init = {}, callerClientConfig) => {
|
|
37
|
-
const { CreateTokenCommand } =
|
|
35
|
+
const { CreateTokenCommand } = require('@aws-sdk/nested-clients/sso-oidc');
|
|
38
36
|
const ssoOidcClient = await getSsoOidcClient(ssoRegion, init, callerClientConfig);
|
|
39
37
|
return ssoOidcClient.send(new CreateTokenCommand({
|
|
40
38
|
clientId: ssoToken.clientId,
|
|
@@ -46,19 +44,19 @@ const getNewSsoOidcToken = async (ssoToken, ssoRegion, init = {}, callerClientCo
|
|
|
46
44
|
|
|
47
45
|
const validateTokenExpiry = (token) => {
|
|
48
46
|
if (token.expiration && token.expiration.getTime() < Date.now()) {
|
|
49
|
-
throw new
|
|
47
|
+
throw new TokenProviderError(`Token is expired. ${REFRESH_MESSAGE}`, false);
|
|
50
48
|
}
|
|
51
49
|
};
|
|
52
50
|
|
|
53
51
|
const validateTokenKey = (key, value, forRefresh = false) => {
|
|
54
52
|
if (typeof value === "undefined") {
|
|
55
|
-
throw new
|
|
53
|
+
throw new TokenProviderError(`Value not present for '${key}' in SSO Token${forRefresh ? ". Cannot refresh" : ""}. ${REFRESH_MESSAGE}`, false);
|
|
56
54
|
}
|
|
57
55
|
};
|
|
58
56
|
|
|
59
|
-
const { writeFile } =
|
|
57
|
+
const { writeFile } = promises;
|
|
60
58
|
const writeSSOTokenToFile = (id, ssoToken) => {
|
|
61
|
-
const tokenFilepath =
|
|
59
|
+
const tokenFilepath = getSSOTokenFilepath(id);
|
|
62
60
|
const tokenString = JSON.stringify(ssoToken, null, 2);
|
|
63
61
|
return writeFile(tokenFilepath, tokenString);
|
|
64
62
|
};
|
|
@@ -66,36 +64,36 @@ const writeSSOTokenToFile = (id, ssoToken) => {
|
|
|
66
64
|
const lastRefreshAttemptTime = new Date(0);
|
|
67
65
|
const fromSso = (init = {}) => async ({ callerClientConfig } = {}) => {
|
|
68
66
|
init.logger?.debug("@aws-sdk/token-providers - fromSso");
|
|
69
|
-
const profiles = await
|
|
70
|
-
const profileName =
|
|
67
|
+
const profiles = await parseKnownFiles(init);
|
|
68
|
+
const profileName = getProfileName({
|
|
71
69
|
profile: init.profile ?? callerClientConfig?.profile,
|
|
72
70
|
});
|
|
73
71
|
const profile = profiles[profileName];
|
|
74
72
|
if (!profile) {
|
|
75
|
-
throw new
|
|
73
|
+
throw new TokenProviderError(`Profile '${profileName}' could not be found in shared credentials file.`, false);
|
|
76
74
|
}
|
|
77
75
|
else if (!profile["sso_session"]) {
|
|
78
|
-
throw new
|
|
76
|
+
throw new TokenProviderError(`Profile '${profileName}' is missing required property 'sso_session'.`);
|
|
79
77
|
}
|
|
80
78
|
const ssoSessionName = profile["sso_session"];
|
|
81
|
-
const ssoSessions = await
|
|
79
|
+
const ssoSessions = await loadSsoSessionData(init);
|
|
82
80
|
const ssoSession = ssoSessions[ssoSessionName];
|
|
83
81
|
if (!ssoSession) {
|
|
84
|
-
throw new
|
|
82
|
+
throw new TokenProviderError(`Sso session '${ssoSessionName}' could not be found in shared credentials file.`, false);
|
|
85
83
|
}
|
|
86
84
|
for (const ssoSessionRequiredKey of ["sso_start_url", "sso_region"]) {
|
|
87
85
|
if (!ssoSession[ssoSessionRequiredKey]) {
|
|
88
|
-
throw new
|
|
86
|
+
throw new TokenProviderError(`Sso session '${ssoSessionName}' is missing required property '${ssoSessionRequiredKey}'.`, false);
|
|
89
87
|
}
|
|
90
88
|
}
|
|
91
89
|
ssoSession["sso_start_url"];
|
|
92
90
|
const ssoRegion = ssoSession["sso_region"];
|
|
93
91
|
let ssoToken;
|
|
94
92
|
try {
|
|
95
|
-
ssoToken = await
|
|
93
|
+
ssoToken = await getSSOTokenFromFile(ssoSessionName);
|
|
96
94
|
}
|
|
97
95
|
catch (e) {
|
|
98
|
-
throw new
|
|
96
|
+
throw new TokenProviderError(`The SSO session token associated with profile=${profileName} was not found or is invalid. ${REFRESH_MESSAGE}`, false);
|
|
99
97
|
}
|
|
100
98
|
validateTokenKey("accessToken", ssoToken.accessToken);
|
|
101
99
|
validateTokenKey("expiresAt", ssoToken.expiresAt);
|
|
@@ -141,13 +139,13 @@ const fromSso = (init = {}) => async ({ callerClientConfig } = {}) => {
|
|
|
141
139
|
const fromStatic = ({ token, logger }) => async () => {
|
|
142
140
|
logger?.debug("@aws-sdk/token-providers - fromStatic");
|
|
143
141
|
if (!token || !token.token) {
|
|
144
|
-
throw new
|
|
142
|
+
throw new TokenProviderError(`Please pass a valid token to fromStatic`, false);
|
|
145
143
|
}
|
|
146
144
|
return token;
|
|
147
145
|
};
|
|
148
146
|
|
|
149
|
-
const nodeProvider = (init = {}) =>
|
|
150
|
-
throw new
|
|
147
|
+
const nodeProvider = (init = {}) => memoize(chain(fromSso(init), async () => {
|
|
148
|
+
throw new TokenProviderError("Could not load token from any providers", false);
|
|
151
149
|
}), (token) => token.expiration !== undefined && token.expiration.getTime() - Date.now() < 300000, (token) => token.expiration !== undefined);
|
|
152
150
|
|
|
153
151
|
exports.fromEnvSigningName = fromEnvSigningName;
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/token-providers",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1070.0",
|
|
4
4
|
"description": "A collection of token providers",
|
|
5
5
|
"main": "./dist-cjs/index.js",
|
|
6
6
|
"module": "./dist-es/index.js",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "concurrently 'yarn:build:types' 'yarn:build:es' && yarn build:cjs",
|
|
9
9
|
"build:cjs": "node ../../scripts/compilation/inline",
|
|
10
|
-
"build:es": "tsc -p tsconfig.es.json",
|
|
10
|
+
"build:es": "premove dist-es && tsc -p tsconfig.es.json",
|
|
11
11
|
"build:include:deps": "yarn g:turbo run build -F=\"$npm_package_name\"",
|
|
12
|
-
"build:types": "tsc -p tsconfig.types.json",
|
|
12
|
+
"build:types": "premove dist-types && tsc -p tsconfig.types.json",
|
|
13
13
|
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
|
|
14
|
-
"clean": "premove dist-cjs dist-es dist-types
|
|
14
|
+
"clean": "premove dist-cjs dist-es dist-types",
|
|
15
15
|
"extract:docs": "api-extractor run --local",
|
|
16
16
|
"test": "yarn g:vitest run",
|
|
17
17
|
"test:watch": "yarn g:vitest watch",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
},
|
|
30
30
|
"license": "Apache-2.0",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@aws-sdk/core": "^3.974.
|
|
33
|
-
"@aws-sdk/nested-clients": "^3.997.
|
|
34
|
-
"@aws-sdk/types": "^3.973.
|
|
32
|
+
"@aws-sdk/core": "^3.974.21",
|
|
33
|
+
"@aws-sdk/nested-clients": "^3.997.21",
|
|
34
|
+
"@aws-sdk/types": "^3.973.13",
|
|
35
35
|
"@smithy/core": "^3.24.6",
|
|
36
36
|
"@smithy/types": "^4.14.3",
|
|
37
37
|
"tslib": "^2.6.2"
|