@aws-sdk/token-providers 3.1045.0 → 3.1046.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 +18 -19
- package/dist-es/fromEnvSigningName.js +1 -1
- package/dist-es/fromSso.js +1 -2
- package/dist-es/fromStatic.js +1 -1
- package/dist-es/nodeProvider.js +1 -1
- package/dist-es/validateTokenExpiry.js +1 -1
- package/dist-es/validateTokenKey.js +1 -1
- package/dist-es/writeSSOTokenToFile.js +1 -1
- package/dist-types/fromSso.d.ts +1 -1
- package/dist-types/getNewSsoOidcToken.d.ts +1 -1
- package/dist-types/ts3.4/fromSso.d.ts +1 -1
- package/dist-types/ts3.4/getNewSsoOidcToken.d.ts +1 -1
- package/dist-types/ts3.4/writeSSOTokenToFile.d.ts +1 -1
- package/dist-types/writeSSOTokenToFile.d.ts +1 -1
- package/package.json +4 -5
package/dist-cjs/index.js
CHANGED
|
@@ -2,18 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
var client = require('@aws-sdk/core/client');
|
|
4
4
|
var httpAuthSchemes = require('@aws-sdk/core/httpAuthSchemes');
|
|
5
|
-
var
|
|
6
|
-
var sharedIniFileLoader = require('@smithy/shared-ini-file-loader');
|
|
5
|
+
var config = require('@smithy/core/config');
|
|
7
6
|
var node_fs = require('node:fs');
|
|
8
7
|
|
|
9
8
|
const fromEnvSigningName = ({ logger, signingName } = {}) => async () => {
|
|
10
9
|
logger?.debug?.("@aws-sdk/token-providers - fromEnvSigningName");
|
|
11
10
|
if (!signingName) {
|
|
12
|
-
throw new
|
|
11
|
+
throw new config.TokenProviderError("Please pass 'signingName' to compute environment variable key", { logger });
|
|
13
12
|
}
|
|
14
13
|
const bearerTokenKey = httpAuthSchemes.getBearerTokenEnvKey(signingName);
|
|
15
14
|
if (!(bearerTokenKey in process.env)) {
|
|
16
|
-
throw new
|
|
15
|
+
throw new config.TokenProviderError(`Token not present in '${bearerTokenKey}' environment variable`, { logger });
|
|
17
16
|
}
|
|
18
17
|
const token = { token: process.env[bearerTokenKey] };
|
|
19
18
|
client.setTokenFeature(token, "BEARER_SERVICE_ENV_VARS", "3");
|
|
@@ -47,19 +46,19 @@ const getNewSsoOidcToken = async (ssoToken, ssoRegion, init = {}, callerClientCo
|
|
|
47
46
|
|
|
48
47
|
const validateTokenExpiry = (token) => {
|
|
49
48
|
if (token.expiration && token.expiration.getTime() < Date.now()) {
|
|
50
|
-
throw new
|
|
49
|
+
throw new config.TokenProviderError(`Token is expired. ${REFRESH_MESSAGE}`, false);
|
|
51
50
|
}
|
|
52
51
|
};
|
|
53
52
|
|
|
54
53
|
const validateTokenKey = (key, value, forRefresh = false) => {
|
|
55
54
|
if (typeof value === "undefined") {
|
|
56
|
-
throw new
|
|
55
|
+
throw new config.TokenProviderError(`Value not present for '${key}' in SSO Token${forRefresh ? ". Cannot refresh" : ""}. ${REFRESH_MESSAGE}`, false);
|
|
57
56
|
}
|
|
58
57
|
};
|
|
59
58
|
|
|
60
59
|
const { writeFile } = node_fs.promises;
|
|
61
60
|
const writeSSOTokenToFile = (id, ssoToken) => {
|
|
62
|
-
const tokenFilepath =
|
|
61
|
+
const tokenFilepath = config.getSSOTokenFilepath(id);
|
|
63
62
|
const tokenString = JSON.stringify(ssoToken, null, 2);
|
|
64
63
|
return writeFile(tokenFilepath, tokenString);
|
|
65
64
|
};
|
|
@@ -67,36 +66,36 @@ const writeSSOTokenToFile = (id, ssoToken) => {
|
|
|
67
66
|
const lastRefreshAttemptTime = new Date(0);
|
|
68
67
|
const fromSso = (init = {}) => async ({ callerClientConfig } = {}) => {
|
|
69
68
|
init.logger?.debug("@aws-sdk/token-providers - fromSso");
|
|
70
|
-
const profiles = await
|
|
71
|
-
const profileName =
|
|
69
|
+
const profiles = await config.parseKnownFiles(init);
|
|
70
|
+
const profileName = config.getProfileName({
|
|
72
71
|
profile: init.profile ?? callerClientConfig?.profile,
|
|
73
72
|
});
|
|
74
73
|
const profile = profiles[profileName];
|
|
75
74
|
if (!profile) {
|
|
76
|
-
throw new
|
|
75
|
+
throw new config.TokenProviderError(`Profile '${profileName}' could not be found in shared credentials file.`, false);
|
|
77
76
|
}
|
|
78
77
|
else if (!profile["sso_session"]) {
|
|
79
|
-
throw new
|
|
78
|
+
throw new config.TokenProviderError(`Profile '${profileName}' is missing required property 'sso_session'.`);
|
|
80
79
|
}
|
|
81
80
|
const ssoSessionName = profile["sso_session"];
|
|
82
|
-
const ssoSessions = await
|
|
81
|
+
const ssoSessions = await config.loadSsoSessionData(init);
|
|
83
82
|
const ssoSession = ssoSessions[ssoSessionName];
|
|
84
83
|
if (!ssoSession) {
|
|
85
|
-
throw new
|
|
84
|
+
throw new config.TokenProviderError(`Sso session '${ssoSessionName}' could not be found in shared credentials file.`, false);
|
|
86
85
|
}
|
|
87
86
|
for (const ssoSessionRequiredKey of ["sso_start_url", "sso_region"]) {
|
|
88
87
|
if (!ssoSession[ssoSessionRequiredKey]) {
|
|
89
|
-
throw new
|
|
88
|
+
throw new config.TokenProviderError(`Sso session '${ssoSessionName}' is missing required property '${ssoSessionRequiredKey}'.`, false);
|
|
90
89
|
}
|
|
91
90
|
}
|
|
92
91
|
ssoSession["sso_start_url"];
|
|
93
92
|
const ssoRegion = ssoSession["sso_region"];
|
|
94
93
|
let ssoToken;
|
|
95
94
|
try {
|
|
96
|
-
ssoToken = await
|
|
95
|
+
ssoToken = await config.getSSOTokenFromFile(ssoSessionName);
|
|
97
96
|
}
|
|
98
97
|
catch (e) {
|
|
99
|
-
throw new
|
|
98
|
+
throw new config.TokenProviderError(`The SSO session token associated with profile=${profileName} was not found or is invalid. ${REFRESH_MESSAGE}`, false);
|
|
100
99
|
}
|
|
101
100
|
validateTokenKey("accessToken", ssoToken.accessToken);
|
|
102
101
|
validateTokenKey("expiresAt", ssoToken.expiresAt);
|
|
@@ -142,13 +141,13 @@ const fromSso = (init = {}) => async ({ callerClientConfig } = {}) => {
|
|
|
142
141
|
const fromStatic = ({ token, logger }) => async () => {
|
|
143
142
|
logger?.debug("@aws-sdk/token-providers - fromStatic");
|
|
144
143
|
if (!token || !token.token) {
|
|
145
|
-
throw new
|
|
144
|
+
throw new config.TokenProviderError(`Please pass a valid token to fromStatic`, false);
|
|
146
145
|
}
|
|
147
146
|
return token;
|
|
148
147
|
};
|
|
149
148
|
|
|
150
|
-
const nodeProvider = (init = {}) =>
|
|
151
|
-
throw new
|
|
149
|
+
const nodeProvider = (init = {}) => config.memoize(config.chain(fromSso(init), async () => {
|
|
150
|
+
throw new config.TokenProviderError("Could not load token from any providers", false);
|
|
152
151
|
}), (token) => token.expiration !== undefined && token.expiration.getTime() - Date.now() < 300000, (token) => token.expiration !== undefined);
|
|
153
152
|
|
|
154
153
|
exports.fromEnvSigningName = fromEnvSigningName;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { setTokenFeature } from "@aws-sdk/core/client";
|
|
2
2
|
import { getBearerTokenEnvKey } from "@aws-sdk/core/httpAuthSchemes";
|
|
3
|
-
import { TokenProviderError } from "@smithy/
|
|
3
|
+
import { TokenProviderError } from "@smithy/core/config";
|
|
4
4
|
export const fromEnvSigningName = ({ logger, signingName } = {}) => async () => {
|
|
5
5
|
logger?.debug?.("@aws-sdk/token-providers - fromEnvSigningName");
|
|
6
6
|
if (!signingName) {
|
package/dist-es/fromSso.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { TokenProviderError } from "@smithy/
|
|
2
|
-
import { getProfileName, getSSOTokenFromFile, loadSsoSessionData, parseKnownFiles, } from "@smithy/shared-ini-file-loader";
|
|
1
|
+
import { getProfileName, getSSOTokenFromFile, loadSsoSessionData, parseKnownFiles, TokenProviderError, } from "@smithy/core/config";
|
|
3
2
|
import { EXPIRE_WINDOW_MS, REFRESH_MESSAGE } from "./constants";
|
|
4
3
|
import { getNewSsoOidcToken } from "./getNewSsoOidcToken";
|
|
5
4
|
import { validateTokenExpiry } from "./validateTokenExpiry";
|
package/dist-es/fromStatic.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TokenProviderError } from "@smithy/
|
|
1
|
+
import { TokenProviderError } from "@smithy/core/config";
|
|
2
2
|
export const fromStatic = ({ token, logger }) => async () => {
|
|
3
3
|
logger?.debug("@aws-sdk/token-providers - fromStatic");
|
|
4
4
|
if (!token || !token.token) {
|
package/dist-es/nodeProvider.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { chain, memoize, TokenProviderError } from "@smithy/
|
|
1
|
+
import { chain, memoize, TokenProviderError } from "@smithy/core/config";
|
|
2
2
|
import { fromSso } from "./fromSso";
|
|
3
3
|
export const nodeProvider = (init = {}) => memoize(chain(fromSso(init), async () => {
|
|
4
4
|
throw new TokenProviderError("Could not load token from any providers", false);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TokenProviderError } from "@smithy/
|
|
1
|
+
import { TokenProviderError } from "@smithy/core/config";
|
|
2
2
|
import { REFRESH_MESSAGE } from "./constants";
|
|
3
3
|
export const validateTokenExpiry = (token) => {
|
|
4
4
|
if (token.expiration && token.expiration.getTime() < Date.now()) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TokenProviderError } from "@smithy/
|
|
1
|
+
import { TokenProviderError } from "@smithy/core/config";
|
|
2
2
|
import { REFRESH_MESSAGE } from "./constants";
|
|
3
3
|
export const validateTokenKey = (key, value, forRefresh = false) => {
|
|
4
4
|
if (typeof value === "undefined") {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getSSOTokenFilepath } from "@smithy/
|
|
1
|
+
import { getSSOTokenFilepath } from "@smithy/core/config";
|
|
2
2
|
import { promises as fsPromises } from "node:fs";
|
|
3
3
|
const { writeFile } = fsPromises;
|
|
4
4
|
export const writeSSOTokenToFile = (id, ssoToken) => {
|
package/dist-types/fromSso.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CredentialProviderOptions, RuntimeConfigIdentityProvider, TokenIdentity } from "@aws-sdk/types";
|
|
2
|
-
import type { SourceProfileInit } from "@smithy/
|
|
2
|
+
import type { SourceProfileInit } from "@smithy/core/config";
|
|
3
3
|
export interface FromSsoInit extends SourceProfileInit, CredentialProviderOptions {
|
|
4
4
|
/**
|
|
5
5
|
* @see SSOOIDCClientConfig in \@aws-sdk/client-sso-oidc.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AwsIdentityProperties } from "@aws-sdk/types";
|
|
2
|
-
import type { SSOToken } from "@smithy/
|
|
2
|
+
import type { SSOToken } from "@smithy/core/config";
|
|
3
3
|
import type { FromSsoInit } from "./fromSso";
|
|
4
4
|
/**
|
|
5
5
|
* Returns a new SSO OIDC token from SSOOIDC::createToken() API call.
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
RuntimeConfigIdentityProvider,
|
|
4
4
|
TokenIdentity,
|
|
5
5
|
} from "@aws-sdk/types";
|
|
6
|
-
import { SourceProfileInit } from "@smithy/
|
|
6
|
+
import { SourceProfileInit } from "@smithy/core/config";
|
|
7
7
|
export interface FromSsoInit
|
|
8
8
|
extends SourceProfileInit,
|
|
9
9
|
CredentialProviderOptions {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AwsIdentityProperties } from "@aws-sdk/types";
|
|
2
|
-
import { SSOToken } from "@smithy/
|
|
2
|
+
import { SSOToken } from "@smithy/core/config";
|
|
3
3
|
import { FromSsoInit } from "./fromSso";
|
|
4
4
|
export declare const getNewSsoOidcToken: (
|
|
5
5
|
ssoToken: SSOToken,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/token-providers",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1046.0",
|
|
4
4
|
"description": "A collection of token providers",
|
|
5
5
|
"main": "./dist-cjs/index.js",
|
|
6
6
|
"module": "./dist-es/index.js",
|
|
@@ -29,11 +29,10 @@
|
|
|
29
29
|
},
|
|
30
30
|
"license": "Apache-2.0",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@aws-sdk/core": "^3.974.
|
|
33
|
-
"@aws-sdk/nested-clients": "^3.997.
|
|
32
|
+
"@aws-sdk/core": "^3.974.9",
|
|
33
|
+
"@aws-sdk/nested-clients": "^3.997.7",
|
|
34
34
|
"@aws-sdk/types": "^3.973.8",
|
|
35
|
-
"@smithy/
|
|
36
|
-
"@smithy/shared-ini-file-loader": "^4.4.9",
|
|
35
|
+
"@smithy/core": "^3.24.1",
|
|
37
36
|
"@smithy/types": "^4.14.1",
|
|
38
37
|
"tslib": "^2.6.2"
|
|
39
38
|
},
|