@aws-sdk/token-providers 3.183.0 → 3.186.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/CHANGELOG.md CHANGED
@@ -3,6 +3,22 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.186.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.185.0...v3.186.0) (2022-10-06)
7
+
8
+ **Note:** Version bump only for package @aws-sdk/token-providers
9
+
10
+
11
+
12
+
13
+
14
+ # [3.185.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.184.0...v3.185.0) (2022-10-05)
15
+
16
+ **Note:** Version bump only for package @aws-sdk/token-providers
17
+
18
+
19
+
20
+
21
+
6
22
  # [3.183.0](https://github.com/aws/aws-sdk-js-v3/compare/v3.182.0...v3.183.0) (2022-10-03)
7
23
 
8
24
  **Note:** Version bump only for package @aws-sdk/token-providers
@@ -1,2 +1,2 @@
1
- export const EXPIRE_WINDOW_MS = 5 * 60 * 1000;
2
- export const REFRESH_MESSAGE = `To refresh this SSO session run 'aws sso login' with the corresponding profile.`;
1
+ export var EXPIRE_WINDOW_MS = 5 * 60 * 1000;
2
+ export var REFRESH_MESSAGE = "To refresh this SSO session run 'aws sso login' with the corresponding profile.";
@@ -1,3 +1,4 @@
1
+ import { __assign, __awaiter, __generator, __values } from "tslib";
1
2
  import { TokenProviderError } from "@aws-sdk/property-provider";
2
3
  import { getProfileName, getSSOTokenFromFile, loadSsoSessionData, parseKnownFiles, } from "@aws-sdk/shared-ini-file-loader";
3
4
  import { EXPIRE_WINDOW_MS, REFRESH_MESSAGE } from "./constants";
@@ -5,74 +6,105 @@ import { getNewSsoOidcToken } from "./getNewSsoOidcToken";
5
6
  import { validateTokenExpiry } from "./validateTokenExpiry";
6
7
  import { validateTokenKey } from "./validateTokenKey";
7
8
  import { writeSSOTokenToFile } from "./writeSSOTokenToFile";
8
- const lastRefreshAttemptTime = new Date(0);
9
- export const fromSso = (init = {}) => async () => {
10
- const profiles = await parseKnownFiles(init);
11
- const profileName = getProfileName(init);
12
- const profile = profiles[profileName];
13
- if (!profile) {
14
- throw new TokenProviderError(`Profile '${profileName}' could not be found in shared credentials file.`, false);
15
- }
16
- else if (!profile["sso_session"]) {
17
- throw new TokenProviderError(`Profile '${profileName}' is missing required property 'sso_session'.`);
18
- }
19
- const ssoSessionName = profile["sso_session"];
20
- const ssoSessions = await loadSsoSessionData(init);
21
- const ssoSession = ssoSessions[ssoSessionName];
22
- if (!ssoSession) {
23
- throw new TokenProviderError(`Sso session '${ssoSessionName}' could not be found in shared credentials file.`, false);
24
- }
25
- for (const ssoSessionRequiredKey of ["sso_start_url", "sso_region"]) {
26
- if (!ssoSession[ssoSessionRequiredKey]) {
27
- throw new TokenProviderError(`Sso session '${ssoSessionName}' is missing required property '${ssoSessionRequiredKey}'.`, false);
28
- }
29
- }
30
- const ssoStartUrl = ssoSession["sso_start_url"];
31
- const ssoRegion = ssoSession["sso_region"];
32
- let ssoToken;
33
- try {
34
- ssoToken = await getSSOTokenFromFile(ssoSessionName);
35
- }
36
- catch (e) {
37
- throw new TokenProviderError(`The SSO session associated with this profile is invalid. ${REFRESH_MESSAGE}`, false);
38
- }
39
- validateTokenKey("accessToken", ssoToken.accessToken);
40
- validateTokenKey("expiresAt", ssoToken.expiresAt);
41
- const { accessToken, expiresAt } = ssoToken;
42
- const existingToken = { token: accessToken, expiration: new Date(expiresAt) };
43
- if (existingToken.expiration.getTime() - Date.now() > EXPIRE_WINDOW_MS) {
44
- return existingToken;
45
- }
46
- if (Date.now() - lastRefreshAttemptTime.getTime() < 30 * 1000) {
47
- validateTokenExpiry(existingToken);
48
- return existingToken;
49
- }
50
- validateTokenKey("clientId", ssoToken.clientId);
51
- validateTokenKey("clientSecret", ssoToken.clientSecret);
52
- validateTokenKey("refreshToken", ssoToken.refreshToken);
53
- try {
54
- lastRefreshAttemptTime.setTime(Date.now());
55
- const newSsoOidcToken = await getNewSsoOidcToken(ssoToken, ssoRegion);
56
- validateTokenKey("accessToken", newSsoOidcToken.accessToken);
57
- validateTokenKey("expiresIn", newSsoOidcToken.expiresIn);
58
- const newTokenExpiration = new Date(Date.now() + newSsoOidcToken.expiresIn * 1000);
59
- try {
60
- await writeSSOTokenToFile(ssoSessionName, {
61
- ...ssoToken,
62
- accessToken: newSsoOidcToken.accessToken,
63
- expiresAt: newTokenExpiration.toISOString(),
64
- refreshToken: newSsoOidcToken.refreshToken,
65
- });
66
- }
67
- catch (error) {
68
- }
69
- return {
70
- token: newSsoOidcToken.accessToken,
71
- expiration: newTokenExpiration,
72
- };
73
- }
74
- catch (error) {
75
- validateTokenExpiry(existingToken);
76
- return existingToken;
77
- }
9
+ var lastRefreshAttemptTime = new Date(0);
10
+ export var fromSso = function (init) {
11
+ if (init === void 0) { init = {}; }
12
+ return function () { return __awaiter(void 0, void 0, void 0, function () {
13
+ var profiles, profileName, profile, ssoSessionName, ssoSessions, ssoSession, _a, _b, ssoSessionRequiredKey, ssoStartUrl, ssoRegion, ssoToken, e_1, accessToken, expiresAt, existingToken, newSsoOidcToken, newTokenExpiration, error_1, error_2;
14
+ var e_2, _c;
15
+ return __generator(this, function (_d) {
16
+ switch (_d.label) {
17
+ case 0: return [4, parseKnownFiles(init)];
18
+ case 1:
19
+ profiles = _d.sent();
20
+ profileName = getProfileName(init);
21
+ profile = profiles[profileName];
22
+ if (!profile) {
23
+ throw new TokenProviderError("Profile '".concat(profileName, "' could not be found in shared credentials file."), false);
24
+ }
25
+ else if (!profile["sso_session"]) {
26
+ throw new TokenProviderError("Profile '".concat(profileName, "' is missing required property 'sso_session'."));
27
+ }
28
+ ssoSessionName = profile["sso_session"];
29
+ return [4, loadSsoSessionData(init)];
30
+ case 2:
31
+ ssoSessions = _d.sent();
32
+ ssoSession = ssoSessions[ssoSessionName];
33
+ if (!ssoSession) {
34
+ throw new TokenProviderError("Sso session '".concat(ssoSessionName, "' could not be found in shared credentials file."), false);
35
+ }
36
+ try {
37
+ for (_a = __values(["sso_start_url", "sso_region"]), _b = _a.next(); !_b.done; _b = _a.next()) {
38
+ ssoSessionRequiredKey = _b.value;
39
+ if (!ssoSession[ssoSessionRequiredKey]) {
40
+ throw new TokenProviderError("Sso session '".concat(ssoSessionName, "' is missing required property '").concat(ssoSessionRequiredKey, "'."), false);
41
+ }
42
+ }
43
+ }
44
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
45
+ finally {
46
+ try {
47
+ if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
48
+ }
49
+ finally { if (e_2) throw e_2.error; }
50
+ }
51
+ ssoStartUrl = ssoSession["sso_start_url"];
52
+ ssoRegion = ssoSession["sso_region"];
53
+ _d.label = 3;
54
+ case 3:
55
+ _d.trys.push([3, 5, , 6]);
56
+ return [4, getSSOTokenFromFile(ssoSessionName)];
57
+ case 4:
58
+ ssoToken = _d.sent();
59
+ return [3, 6];
60
+ case 5:
61
+ e_1 = _d.sent();
62
+ throw new TokenProviderError("The SSO session associated with this profile is invalid. ".concat(REFRESH_MESSAGE), false);
63
+ case 6:
64
+ validateTokenKey("accessToken", ssoToken.accessToken);
65
+ validateTokenKey("expiresAt", ssoToken.expiresAt);
66
+ accessToken = ssoToken.accessToken, expiresAt = ssoToken.expiresAt;
67
+ existingToken = { token: accessToken, expiration: new Date(expiresAt) };
68
+ if (existingToken.expiration.getTime() - Date.now() > EXPIRE_WINDOW_MS) {
69
+ return [2, existingToken];
70
+ }
71
+ if (Date.now() - lastRefreshAttemptTime.getTime() < 30 * 1000) {
72
+ validateTokenExpiry(existingToken);
73
+ return [2, existingToken];
74
+ }
75
+ validateTokenKey("clientId", ssoToken.clientId);
76
+ validateTokenKey("clientSecret", ssoToken.clientSecret);
77
+ validateTokenKey("refreshToken", ssoToken.refreshToken);
78
+ _d.label = 7;
79
+ case 7:
80
+ _d.trys.push([7, 13, , 14]);
81
+ lastRefreshAttemptTime.setTime(Date.now());
82
+ return [4, getNewSsoOidcToken(ssoToken, ssoRegion)];
83
+ case 8:
84
+ newSsoOidcToken = _d.sent();
85
+ validateTokenKey("accessToken", newSsoOidcToken.accessToken);
86
+ validateTokenKey("expiresIn", newSsoOidcToken.expiresIn);
87
+ newTokenExpiration = new Date(Date.now() + newSsoOidcToken.expiresIn * 1000);
88
+ _d.label = 9;
89
+ case 9:
90
+ _d.trys.push([9, 11, , 12]);
91
+ return [4, writeSSOTokenToFile(ssoSessionName, __assign(__assign({}, ssoToken), { accessToken: newSsoOidcToken.accessToken, expiresAt: newTokenExpiration.toISOString(), refreshToken: newSsoOidcToken.refreshToken }))];
92
+ case 10:
93
+ _d.sent();
94
+ return [3, 12];
95
+ case 11:
96
+ error_1 = _d.sent();
97
+ return [3, 12];
98
+ case 12: return [2, {
99
+ token: newSsoOidcToken.accessToken,
100
+ expiration: newTokenExpiration,
101
+ }];
102
+ case 13:
103
+ error_2 = _d.sent();
104
+ validateTokenExpiry(existingToken);
105
+ return [2, existingToken];
106
+ case 14: return [2];
107
+ }
108
+ });
109
+ }); };
78
110
  };
@@ -1,7 +1,13 @@
1
+ import { __awaiter, __generator } from "tslib";
1
2
  import { TokenProviderError } from "@aws-sdk/property-provider";
2
- export const fromStatic = ({ token }) => async () => {
3
- if (!token || !token.token) {
4
- throw new TokenProviderError(`Please pass a valid token to fromStatic`, false);
5
- }
6
- return token;
3
+ export var fromStatic = function (_a) {
4
+ var token = _a.token;
5
+ return function () { return __awaiter(void 0, void 0, void 0, function () {
6
+ return __generator(this, function (_a) {
7
+ if (!token || !token.token) {
8
+ throw new TokenProviderError("Please pass a valid token to fromStatic", false);
9
+ }
10
+ return [2, token];
11
+ });
12
+ }); };
7
13
  };
@@ -1,7 +1,7 @@
1
1
  import { CreateTokenCommand } from "@aws-sdk/client-sso-oidc";
2
2
  import { getSsoOidcClient } from "./getSsoOidcClient";
3
- export const getNewSsoOidcToken = (ssoToken, ssoRegion) => {
4
- const ssoOidcClient = getSsoOidcClient(ssoRegion);
3
+ export var getNewSsoOidcToken = function (ssoToken, ssoRegion) {
4
+ var ssoOidcClient = getSsoOidcClient(ssoRegion);
5
5
  return ssoOidcClient.send(new CreateTokenCommand({
6
6
  clientId: ssoToken.clientId,
7
7
  clientSecret: ssoToken.clientSecret,
@@ -1,10 +1,10 @@
1
1
  import { SSOOIDCClient } from "@aws-sdk/client-sso-oidc";
2
- const ssoOidcClientsHash = {};
3
- export const getSsoOidcClient = (ssoRegion) => {
2
+ var ssoOidcClientsHash = {};
3
+ export var getSsoOidcClient = function (ssoRegion) {
4
4
  if (ssoOidcClientsHash[ssoRegion]) {
5
5
  return ssoOidcClientsHash[ssoRegion];
6
6
  }
7
- const ssoOidcClient = new SSOOIDCClient({ region: ssoRegion });
7
+ var ssoOidcClient = new SSOOIDCClient({ region: ssoRegion });
8
8
  ssoOidcClientsHash[ssoRegion] = ssoOidcClient;
9
9
  return ssoOidcClient;
10
10
  };
@@ -1,5 +1,11 @@
1
+ import { __awaiter, __generator } from "tslib";
1
2
  import { chain, memoize, TokenProviderError } from "@aws-sdk/property-provider";
2
3
  import { fromSso } from "./fromSso";
3
- export const nodeProvider = (init = {}) => memoize(chain(fromSso(init), async () => {
4
- throw new TokenProviderError("Could not load token from any providers", false);
5
- }), (token) => token.expiration !== undefined && token.expiration.getTime() - Date.now() < 300000, (token) => token.expiration !== undefined);
4
+ export var nodeProvider = function (init) {
5
+ if (init === void 0) { init = {}; }
6
+ return memoize(chain(fromSso(init), function () { return __awaiter(void 0, void 0, void 0, function () {
7
+ return __generator(this, function (_a) {
8
+ throw new TokenProviderError("Could not load token from any providers", false);
9
+ });
10
+ }); }), function (token) { return token.expiration !== undefined && token.expiration.getTime() - Date.now() < 300000; }, function (token) { return token.expiration !== undefined; });
11
+ };
@@ -1,7 +1,7 @@
1
1
  import { TokenProviderError } from "@aws-sdk/property-provider";
2
2
  import { REFRESH_MESSAGE } from "./constants";
3
- export const validateTokenExpiry = (token) => {
3
+ export var validateTokenExpiry = function (token) {
4
4
  if (token.expiration && token.expiration.getTime() < Date.now()) {
5
- throw new TokenProviderError(`Token is expired. ${REFRESH_MESSAGE}`, false);
5
+ throw new TokenProviderError("Token is expired. ".concat(REFRESH_MESSAGE), false);
6
6
  }
7
7
  };
@@ -1,7 +1,7 @@
1
1
  import { TokenProviderError } from "@aws-sdk/property-provider";
2
2
  import { REFRESH_MESSAGE } from "./constants";
3
- export const validateTokenKey = (key, value) => {
3
+ export var validateTokenKey = function (key, value) {
4
4
  if (typeof value === "undefined") {
5
- throw new TokenProviderError(`Value not present for '${key}' in SSO Token'. ${REFRESH_MESSAGE}`, false);
5
+ throw new TokenProviderError("Value not present for '".concat(key, "' in SSO Token'. ").concat(REFRESH_MESSAGE), false);
6
6
  }
7
7
  };
@@ -1,8 +1,8 @@
1
1
  import { getSSOTokenFilepath } from "@aws-sdk/shared-ini-file-loader";
2
2
  import { promises as fsPromises } from "fs";
3
- const { writeFile } = fsPromises;
4
- export const writeSSOTokenToFile = (ssoStartUrl, ssoToken) => {
5
- const tokenFilepath = getSSOTokenFilepath(ssoStartUrl);
6
- const tokenString = JSON.stringify(ssoToken, null, 2);
3
+ var writeFile = fsPromises.writeFile;
4
+ export var writeSSOTokenToFile = function (ssoStartUrl, ssoToken) {
5
+ var tokenFilepath = getSSOTokenFilepath(ssoStartUrl);
6
+ var tokenString = JSON.stringify(ssoToken, null, 2);
7
7
  return writeFile(tokenFilepath, tokenString);
8
8
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/token-providers",
3
- "version": "3.183.0",
3
+ "version": "3.186.0",
4
4
  "description": "A collection of token providers",
5
5
  "main": "./dist-cjs/index.js",
6
6
  "module": "./dist-es/index.js",
@@ -25,10 +25,10 @@
25
25
  },
26
26
  "license": "Apache-2.0",
27
27
  "dependencies": {
28
- "@aws-sdk/client-sso-oidc": "3.183.0",
29
- "@aws-sdk/property-provider": "3.183.0",
30
- "@aws-sdk/shared-ini-file-loader": "3.183.0",
31
- "@aws-sdk/types": "3.183.0",
28
+ "@aws-sdk/client-sso-oidc": "3.186.0",
29
+ "@aws-sdk/property-provider": "3.186.0",
30
+ "@aws-sdk/shared-ini-file-loader": "3.186.0",
31
+ "@aws-sdk/types": "3.186.0",
32
32
  "tslib": "^2.3.1"
33
33
  },
34
34
  "devDependencies": {