@aws-sdk/credential-providers 3.32.0 → 3.36.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.
Files changed (97) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/dist-cjs/fromCognitoIdentity.js +13 -0
  3. package/dist-cjs/fromCognitoIdentityPool.js +13 -0
  4. package/dist-cjs/fromContainerMetadata.js +6 -0
  5. package/dist-cjs/fromEnv.js +6 -0
  6. package/dist-cjs/fromIni.js +14 -0
  7. package/dist-cjs/fromInstanceMetadata.js +6 -0
  8. package/dist-cjs/fromProcess.js +6 -0
  9. package/dist-cjs/fromSSO.js +7 -0
  10. package/dist-cjs/fromTemporaryCredentials.js +31 -0
  11. package/dist-cjs/fromTokenFile.js +13 -0
  12. package/dist-cjs/fromWebToken.js +13 -0
  13. package/dist-cjs/index.js +14 -0
  14. package/dist-es/fromCognitoIdentity.js +7 -0
  15. package/dist-es/fromCognitoIdentityPool.js +7 -0
  16. package/dist-es/fromContainerMetadata.js +2 -0
  17. package/dist-es/fromEnv.js +2 -0
  18. package/dist-es/fromIni.js +8 -0
  19. package/dist-es/fromInstanceMetadata.js +2 -0
  20. package/dist-es/fromProcess.js +2 -0
  21. package/dist-es/fromSSO.js +7 -0
  22. package/dist-es/fromTemporaryCredentials.js +40 -0
  23. package/dist-es/fromTokenFile.js +8 -0
  24. package/dist-es/fromWebToken.js +7 -0
  25. package/{dist/types/index.d.ts → dist-es/index.js} +0 -0
  26. package/{dist/types → dist-types}/fromCognitoIdentity.d.ts +0 -0
  27. package/{dist/types → dist-types}/fromCognitoIdentityPool.d.ts +0 -0
  28. package/{dist/types → dist-types}/fromContainerMetadata.d.ts +0 -0
  29. package/{dist/types → dist-types}/fromEnv.d.ts +0 -0
  30. package/{dist/types → dist-types}/fromIni.d.ts +0 -0
  31. package/{dist/types → dist-types}/fromInstanceMetadata.d.ts +0 -0
  32. package/{dist/types → dist-types}/fromProcess.d.ts +0 -0
  33. package/{dist/types → dist-types}/fromSSO.d.ts +0 -0
  34. package/{dist/types → dist-types}/fromTemporaryCredentials.d.ts +0 -0
  35. package/{dist/types → dist-types}/fromTokenFile.d.ts +0 -0
  36. package/{dist/types → dist-types}/fromWebToken.d.ts +0 -0
  37. package/{src/index.ts → dist-types/index.d.ts} +0 -0
  38. package/{dist/types → dist-types}/ts3.4/fromCognitoIdentity.d.ts +0 -0
  39. package/{dist/types → dist-types}/ts3.4/fromCognitoIdentityPool.d.ts +0 -0
  40. package/{dist/types → dist-types}/ts3.4/fromContainerMetadata.d.ts +0 -0
  41. package/{dist/types → dist-types}/ts3.4/fromEnv.d.ts +0 -0
  42. package/{dist/types → dist-types}/ts3.4/fromIni.d.ts +0 -0
  43. package/{dist/types → dist-types}/ts3.4/fromInstanceMetadata.d.ts +0 -0
  44. package/{dist/types → dist-types}/ts3.4/fromProcess.d.ts +0 -0
  45. package/{dist/types → dist-types}/ts3.4/fromSSO.d.ts +0 -0
  46. package/{dist/types → dist-types}/ts3.4/fromTemporaryCredentials.d.ts +0 -0
  47. package/{dist/types → dist-types}/ts3.4/fromTokenFile.d.ts +0 -0
  48. package/{dist/types → dist-types}/ts3.4/fromWebToken.d.ts +0 -0
  49. package/{dist/types → dist-types}/ts3.4/index.d.ts +0 -0
  50. package/package.json +26 -22
  51. package/dist/cjs/fromCognitoIdentity.js +0 -49
  52. package/dist/cjs/fromCognitoIdentityPool.js +0 -54
  53. package/dist/cjs/fromContainerMetadata.js +0 -26
  54. package/dist/cjs/fromEnv.js +0 -31
  55. package/dist/cjs/fromIni.js +0 -51
  56. package/dist/cjs/fromInstanceMetadata.js +0 -26
  57. package/dist/cjs/fromProcess.js +0 -30
  58. package/dist/cjs/fromSSO.js +0 -49
  59. package/dist/cjs/fromTemporaryCredentials.js +0 -69
  60. package/dist/cjs/fromTokenFile.js +0 -39
  61. package/dist/cjs/fromWebToken.js +0 -48
  62. package/dist/cjs/index.js +0 -15
  63. package/dist/es/fromCognitoIdentity.js +0 -43
  64. package/dist/es/fromCognitoIdentityPool.js +0 -48
  65. package/dist/es/fromContainerMetadata.js +0 -22
  66. package/dist/es/fromEnv.js +0 -27
  67. package/dist/es/fromIni.js +0 -45
  68. package/dist/es/fromInstanceMetadata.js +0 -22
  69. package/dist/es/fromProcess.js +0 -26
  70. package/dist/es/fromSSO.js +0 -49
  71. package/dist/es/fromTemporaryCredentials.js +0 -78
  72. package/dist/es/fromTokenFile.js +0 -34
  73. package/dist/es/fromWebToken.js +0 -42
  74. package/dist/es/index.js +0 -12
  75. package/dist/tsconfig.cjs.tsbuildinfo +0 -1
  76. package/dist/tsconfig.es.tsbuildinfo +0 -1
  77. package/jest.config.js +0 -5
  78. package/src/fromCognitoIdentity.spec.ts +0 -42
  79. package/src/fromCognitoIdentity.ts +0 -56
  80. package/src/fromCognitoIdentityPool.spec.ts +0 -47
  81. package/src/fromCognitoIdentityPool.ts +0 -58
  82. package/src/fromContainerMetadata.ts +0 -28
  83. package/src/fromEnv.ts +0 -28
  84. package/src/fromIni.spec.ts +0 -58
  85. package/src/fromIni.ts +0 -51
  86. package/src/fromInstanceMetadata.ts +0 -26
  87. package/src/fromProcess.ts +0 -29
  88. package/src/fromSSO.spec.ts +0 -26
  89. package/src/fromSSO.ts +0 -51
  90. package/src/fromTemporaryCredentials.spec.ts +0 -199
  91. package/src/fromTemporaryCredentials.ts +0 -74
  92. package/src/fromTokenFile.spec.ts +0 -41
  93. package/src/fromTokenFile.ts +0 -42
  94. package/src/fromWebToken.spec.ts +0 -51
  95. package/src/fromWebToken.ts +0 -51
  96. package/tsconfig.cjs.json +0 -10
  97. package/tsconfig.es.json +0 -11
@@ -1,199 +0,0 @@
1
- const sendMock = jest.fn();
2
- jest.mock("@aws-sdk/client-sts", () => ({
3
- STSClient: jest.fn().mockImplementation(function (config) {
4
- this.config = config;
5
- this.send = jest.fn().mockImplementation(async function (command) {
6
- // Mock resolving client credentials provider at send()
7
- if (typeof this.config.credentials === "function") this.config.credentials = await this.config.credentials();
8
- return await sendMock(command);
9
- });
10
- return this;
11
- }),
12
- AssumeRoleCommand: jest.fn().mockImplementation(function (params) {
13
- // Return the input so we can assert the input parameters in client's send()
14
- return {
15
- input: params,
16
- command: "ASSUME_ROLE",
17
- };
18
- }),
19
- }));
20
-
21
- import { AssumeRoleCommand, STSClient } from "@aws-sdk/client-sts";
22
-
23
- import { fromTemporaryCredentials } from "./fromTemporaryCredentials";
24
-
25
- describe("fromTemporaryCredentials", () => {
26
- const RoleArn = "ROLE_ARN";
27
- const RoleSessionName = "ROLE_SESSION_NAME";
28
- const masterCredentials = {
29
- accessKeyId: "ACCESS_KEY_ID",
30
- secretAccessKey: "SECRET_ACCESS_KEY",
31
- };
32
- const region = "US_BAR_1";
33
-
34
- beforeEach(() => {
35
- jest.clearAllMocks();
36
- sendMock.mockResolvedValueOnce({
37
- Credentials: {
38
- AccessKeyId: "ACCESS_KEY_ID",
39
- SecretAccessKey: "SECRET_ACCESS_KEY",
40
- SessionToken: "SESSION_TOKEN",
41
- },
42
- });
43
- });
44
-
45
- it("should call STS::AssumeRole API with master credentials", async () => {
46
- const options = {
47
- params: {
48
- RoleArn,
49
- RoleSessionName,
50
- },
51
- masterCredentials,
52
- clientConfig: { region },
53
- };
54
- const provider = fromTemporaryCredentials(options);
55
- const credential = await provider();
56
- expect(credential).toEqual({
57
- accessKeyId: "ACCESS_KEY_ID",
58
- secretAccessKey: "SECRET_ACCESS_KEY",
59
- sessionToken: "SESSION_TOKEN",
60
- });
61
- expect(STSClient as jest.Mock).toBeCalledWith({
62
- credentials: masterCredentials,
63
- region,
64
- });
65
- expect(AssumeRoleCommand as jest.Mock).toBeCalledWith({
66
- RoleArn,
67
- RoleSessionName,
68
- });
69
- expect(sendMock as jest.Mock).toBeCalledWith({ command: "ASSUME_ROLE", input: options.params });
70
- });
71
-
72
- it("should create STS client if not supplied", async () => {
73
- const provider = fromTemporaryCredentials({
74
- params: {
75
- RoleArn,
76
- RoleSessionName,
77
- },
78
- masterCredentials,
79
- });
80
- await provider();
81
- expect(STSClient as jest.Mock).toBeCalledWith({
82
- credentials: masterCredentials,
83
- });
84
- });
85
-
86
- it("should resolve default credentials if master credential is not supplied", async () => {
87
- const provider = fromTemporaryCredentials({
88
- params: {
89
- RoleArn,
90
- RoleSessionName,
91
- },
92
- });
93
- await provider();
94
- expect(STSClient as jest.Mock).toBeCalledWith({});
95
- });
96
-
97
- it("should create a role session name if none provided", async () => {
98
- const provider = fromTemporaryCredentials({
99
- params: { RoleArn },
100
- });
101
- await provider();
102
- expect(AssumeRoleCommand as jest.Mock).toBeCalledWith({
103
- RoleArn,
104
- RoleSessionName: expect.stringMatching(/^aws-sdk-js-/),
105
- });
106
- });
107
-
108
- it("should allow assume roles assuming roles assuming roles ad infinitum", async () => {
109
- const roleArnOf = (id: string) => `arn:aws:iam::123456789:role/${id}`;
110
- const idOf = (roleArn: string) => roleArn.split("/")?.[1] ?? "UNKNOWN";
111
- const provider = fromTemporaryCredentials({
112
- params: { RoleArn: roleArnOf("third") },
113
- masterCredentials: fromTemporaryCredentials({
114
- params: { RoleArn: roleArnOf("second") },
115
- masterCredentials: fromTemporaryCredentials({
116
- params: { RoleArn: roleArnOf("first") },
117
- }),
118
- }),
119
- });
120
- sendMock.mockReset().mockImplementation((mockCommand) => ({
121
- Credentials: {
122
- AccessKeyId: `access_id_from_${idOf(mockCommand.input.RoleArn)}`,
123
- SecretAccessKey: "SECRET_ACCESS_KEY",
124
- SessionToken: "SESSION_TOKEN",
125
- },
126
- }));
127
- const credentials = await provider();
128
- expect(sendMock.mock.calls.length).toBe(3);
129
- expect((AssumeRoleCommand as jest.Mock).mock.calls.length).toBe(3);
130
- expect(credentials.accessKeyId).toBe("access_id_from_third");
131
- // Creates STS Client with right master credentials and assume role with
132
- // expected role arn.
133
- expect((STSClient as jest.Mock).mock.results.length).toBe(3);
134
- const outmostClient = (STSClient as jest.Mock).mock.results[0].value;
135
- expect(outmostClient.config.credentials).toEqual(expect.objectContaining({ accessKeyId: "access_id_from_second" }));
136
- expect((outmostClient.send as jest.Mock).mock.calls.length).toBe(1);
137
- expect((outmostClient.send as jest.Mock).mock.calls[0][0].input).toEqual(
138
- expect.objectContaining({ RoleArn: roleArnOf("third") })
139
- );
140
-
141
- const middleClient = (STSClient as jest.Mock).mock.results[1].value;
142
- expect(middleClient.config.credentials).toEqual(expect.objectContaining({ accessKeyId: "access_id_from_first" }));
143
- expect((middleClient.send as jest.Mock).mock.calls.length).toBe(1);
144
- expect((middleClient.send as jest.Mock).mock.calls[0][0].input).toEqual(
145
- expect.objectContaining({ RoleArn: roleArnOf("second") })
146
- );
147
-
148
- const innermostClient = (STSClient as jest.Mock).mock.results[2].value;
149
- expect(innermostClient.config.credentials).toEqual(undefined);
150
- expect((innermostClient.send as jest.Mock).mock.calls.length).toBe(1);
151
- expect((innermostClient.send as jest.Mock).mock.calls[0][0].input).toEqual(
152
- expect.objectContaining({ RoleArn: roleArnOf("first") })
153
- );
154
-
155
- // Call assume role API with expected chronological order
156
- expect(sendMock.mock.calls[0][0].input).toEqual(expect.objectContaining({ RoleArn: roleArnOf("first") }));
157
- expect(sendMock.mock.calls[1][0].input).toEqual(expect.objectContaining({ RoleArn: roleArnOf("second") }));
158
- expect(sendMock.mock.calls[2][0].input).toEqual(expect.objectContaining({ RoleArn: roleArnOf("third") }));
159
-
160
- // Should not create extra clients if credentials is still valid
161
- await provider();
162
- expect((STSClient as jest.Mock).mock.results.length).toBe(3);
163
- });
164
-
165
- it("should support assuming a role with multi-factor authentication", async () => {
166
- const SerialNumber = "SERIAL_NUMBER";
167
- const mfaCode = "MFA_CODE";
168
- const mfaCodeProvider = jest.fn().mockResolvedValue(mfaCode);
169
- const provider = fromTemporaryCredentials({
170
- params: { RoleArn, SerialNumber, RoleSessionName },
171
- mfaCodeProvider,
172
- });
173
- await provider();
174
- expect(mfaCodeProvider).toBeCalledWith(SerialNumber);
175
- expect(sendMock).toBeCalledWith(
176
- expect.objectContaining({
177
- input: {
178
- RoleArn,
179
- RoleSessionName,
180
- SerialNumber,
181
- TokenCode: mfaCode,
182
- },
183
- })
184
- );
185
- });
186
-
187
- it("should reject the promise with a terminal error if a MFA serial presents but mfaCodeProvider is missing", async () => {
188
- const SerialNumber = "SERIAL_NUMBER";
189
- try {
190
- await fromTemporaryCredentials({
191
- params: { RoleArn, SerialNumber, RoleSessionName },
192
- })();
193
- fail("this test must fail");
194
- } catch (e) {
195
- expect(e.message).toEqual(expect.stringContaining("Temporary credential requires multi-factor authentication"));
196
- expect(e.tryNextLink).toBe(false);
197
- }
198
- });
199
- });
@@ -1,74 +0,0 @@
1
- import { AssumeRoleCommand, AssumeRoleCommandInput, STSClient, STSClientConfig } from "@aws-sdk/client-sts";
2
- import { CredentialsProviderError } from "@aws-sdk/property-provider";
3
- import { CredentialProvider, Credentials } from "@aws-sdk/types";
4
-
5
- export interface FromTemporaryCredentialsOptions {
6
- params: Omit<AssumeRoleCommandInput, "RoleSessionName"> & { RoleSessionName?: string };
7
- masterCredentials?: Credentials | CredentialProvider;
8
- clientConfig?: STSClientConfig;
9
- mfaCodeProvider?: (mfaSerial: string) => Promise<string>;
10
- }
11
-
12
- /**
13
- * Creates a credential provider function that retrieves temporary credentials from STS AssumeRole API.
14
- *
15
- * ```javascript
16
- * import { fromTemporaryCredentials } from "@aws-sdk/credential-providers"; // ES6 import
17
- * // const { fromTemporaryCredentials } = require("@aws-sdk/credential-providers"); // CommonJS import
18
- *
19
- * const client = new FooClient({
20
- * region,
21
- * credentials: fromTemporaryCredentials(
22
- * // Optional. The master credentials used to get and refresh temporary credentials from AWS STS. If skipped, it uses
23
- * // the default credential resolved by internal STS client.
24
- * masterCredentials: fromTemporaryCredentials({
25
- * params: { RoleArn: "arn:aws:iam::1234567890:role/RoleA" }
26
- * }),
27
- * // Required. Options passed to STS AssumeRole operation.
28
- * params: {
29
- * // Required. ARN of role to assume.
30
- * RoleArn: "arn:aws:iam::1234567890:role/RoleB",
31
- * // Optional. An identifier for the assumed role session. If skipped, it generates a random session name with
32
- * // prefix of 'aws-sdk-js-'.
33
- * RoleSessionName: "aws-sdk-js-123",
34
- * // Optional. The duration, in seconds, of the role session.
35
- * DurationSeconds: 3600
36
- * //... For more options see https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html
37
- * },
38
- * // Optional. Custom STS client configurations overriding the default ones.
39
- * clientConfig: { region },
40
- * // Optional. A function that returns a promise fulfilled with an MFA token code for the provided MFA Serial code.
41
- * // Required if `params` has `SerialNumber` config.
42
- * mfaCodeProvider: async mfaSerial => {
43
- * return "token"
44
- * }
45
- * ),
46
- * });
47
- * ```
48
- */
49
- export const fromTemporaryCredentials = (options: FromTemporaryCredentialsOptions): CredentialProvider => {
50
- let stsClient: STSClient;
51
- return async (): Promise<Credentials> => {
52
- const params = { ...options.params, RoleSessionName: options.params.RoleSessionName ?? "aws-sdk-js-" + Date.now() };
53
- if (params?.SerialNumber) {
54
- if (!options.mfaCodeProvider) {
55
- throw new CredentialsProviderError(
56
- `Temporary credential requires multi-factor authentication,` + ` but no MFA code callback was provided.`,
57
- false
58
- );
59
- }
60
- params.TokenCode = await options.mfaCodeProvider(params?.SerialNumber);
61
- }
62
- if (!stsClient) stsClient = new STSClient({ ...options.clientConfig, credentials: options.masterCredentials });
63
- const { Credentials } = await stsClient.send(new AssumeRoleCommand(params));
64
- if (!Credentials || !Credentials.AccessKeyId || !Credentials.SecretAccessKey) {
65
- throw new CredentialsProviderError(`Invalid response from STS.assumeRole call with role ${params.RoleArn}`);
66
- }
67
- return {
68
- accessKeyId: Credentials.AccessKeyId,
69
- secretAccessKey: Credentials.SecretAccessKey,
70
- sessionToken: Credentials.SessionToken,
71
- expiration: Credentials.Expiration,
72
- };
73
- };
74
- };
@@ -1,41 +0,0 @@
1
- const ROLE_ASSUMER_WITH_WEB_IDENTITY = "ROLE_ASSUMER_WITH_WEB_IDENTITY";
2
-
3
- jest.mock("@aws-sdk/client-sts", () => ({
4
- getDefaultRoleAssumerWithWebIdentity: jest.fn().mockReturnValue(ROLE_ASSUMER_WITH_WEB_IDENTITY),
5
- }));
6
-
7
- import { getDefaultRoleAssumerWithWebIdentity } from "@aws-sdk/client-sts";
8
- import { fromTokenFile as coreProvider } from "@aws-sdk/credential-provider-web-identity";
9
-
10
- import { fromTokenFile } from "./fromTokenFile";
11
-
12
- jest.mock("@aws-sdk/credential-provider-web-identity", () => ({
13
- fromTokenFile: jest.fn(),
14
- }));
15
-
16
- describe("fromTokenFile", () => {
17
- beforeEach(() => {
18
- jest.clearAllMocks();
19
- });
20
-
21
- it("should inject default role assumer", () => {
22
- fromTokenFile();
23
- expect(coreProvider).toBeCalledWith({
24
- roleAssumerWithWebIdentity: ROLE_ASSUMER_WITH_WEB_IDENTITY,
25
- });
26
- expect(getDefaultRoleAssumerWithWebIdentity).toBeCalled();
27
- });
28
-
29
- it("should supply sts config to role assumer", () => {
30
- const clientConfig = {
31
- region: "US_FOO_0",
32
- };
33
- fromTokenFile({
34
- clientConfig,
35
- });
36
- expect((coreProvider as jest.Mock).mock.calls[0][0]).toMatchObject({
37
- roleAssumerWithWebIdentity: ROLE_ASSUMER_WITH_WEB_IDENTITY,
38
- });
39
- expect(getDefaultRoleAssumerWithWebIdentity).toBeCalledWith(clientConfig);
40
- });
41
- });
@@ -1,42 +0,0 @@
1
- import { getDefaultRoleAssumerWithWebIdentity, STSClientConfig } from "@aws-sdk/client-sts";
2
- import {
3
- fromTokenFile as _fromTokenFile,
4
- FromTokenFileInit as _FromTokenFileInit,
5
- } from "@aws-sdk/credential-provider-web-identity";
6
- import { CredentialProvider } from "@aws-sdk/types";
7
-
8
- export interface FromTokenFileInit extends _FromTokenFileInit {
9
- clientConfig?: STSClientConfig;
10
- }
11
-
12
- /**
13
- * Creates a credential provider function that reads OIDC token from given file, then call STS.AssumeRoleWithWebIdentity
14
- * API. The configurations must be specified in environmental variables:
15
- *
16
- * - Reads file location of where the OIDC token is stored from either provided option `webIdentityTokenFile` or
17
- * environment variable `AWS_WEB_IDENTITY_TOKEN_FILE`.
18
- * - Reads IAM role wanting to be assumed from either provided option `roleArn` or environment variable `AWS_ROLE_ARN`.
19
- * - Reads optional role session name to be used to distinguish sessions from provided option `roleSessionName` or
20
- * environment variable `AWS_ROLE_SESSION_NAME`.
21
- * If session name is not defined, it comes up with a role session name.
22
- * - Reads OIDC token from file on disk.
23
- * - Calls sts:AssumeRoleWithWebIdentity via `roleAssumerWithWebIdentity` option to get credentials.
24
- *
25
- * ```javascript
26
- * import { fromTokenFile } from "@aws-sdk/credential-providers"; // ES6 import
27
- * // const { fromTokenFile } = require("@aws-sdk/credential-providers"); // CommonJS import
28
- *
29
- * const client = new FooClient({
30
- * credentials: fromTokenFile({
31
- * // Optional. STS client config to make the assume role request.
32
- * clientConfig: { region }
33
- * });
34
- * });
35
- * ```
36
- */
37
- export const fromTokenFile = (init: FromTokenFileInit = {}): CredentialProvider =>
38
- _fromTokenFile({
39
- ...init,
40
- roleAssumerWithWebIdentity:
41
- init.roleAssumerWithWebIdentity ?? getDefaultRoleAssumerWithWebIdentity(init.clientConfig),
42
- });
@@ -1,51 +0,0 @@
1
- const ROLE_ASSUMER_WITH_WEB_IDENTITY = "ROLE_ASSUMER_WITH_WEB_IDENTITY";
2
-
3
- jest.mock("@aws-sdk/client-sts", () => ({
4
- getDefaultRoleAssumerWithWebIdentity: jest.fn().mockReturnValue(ROLE_ASSUMER_WITH_WEB_IDENTITY),
5
- }));
6
-
7
- import { getDefaultRoleAssumerWithWebIdentity } from "@aws-sdk/client-sts";
8
- import { fromWebToken as coreProvider } from "@aws-sdk/credential-provider-web-identity";
9
-
10
- import { fromWebToken } from "./fromWebToken";
11
-
12
- jest.mock("@aws-sdk/credential-provider-web-identity", () => ({
13
- fromWebToken: jest.fn(),
14
- }));
15
-
16
- describe("fromWebToken", () => {
17
- const roleArn = "ROLE_ARN";
18
- const webIdentityToken = "WEB_IDENTITY_TOKEN";
19
-
20
- beforeEach(() => {
21
- jest.clearAllMocks();
22
- });
23
-
24
- it("should inject default role assumer", () => {
25
- fromWebToken({
26
- roleArn,
27
- webIdentityToken,
28
- });
29
- expect(coreProvider).toBeCalledWith({
30
- roleArn,
31
- webIdentityToken,
32
- roleAssumerWithWebIdentity: ROLE_ASSUMER_WITH_WEB_IDENTITY,
33
- });
34
- expect(getDefaultRoleAssumerWithWebIdentity).toBeCalled();
35
- });
36
-
37
- it("should supply sts config to role assumer", () => {
38
- const clientConfig = {
39
- region: "US_FOO_0",
40
- };
41
- fromWebToken({
42
- roleArn,
43
- webIdentityToken,
44
- clientConfig,
45
- });
46
- expect((coreProvider as jest.Mock).mock.calls[0][0]).toMatchObject({
47
- roleAssumerWithWebIdentity: ROLE_ASSUMER_WITH_WEB_IDENTITY,
48
- });
49
- expect(getDefaultRoleAssumerWithWebIdentity).toBeCalledWith(clientConfig);
50
- });
51
- });
@@ -1,51 +0,0 @@
1
- import { getDefaultRoleAssumerWithWebIdentity, STSClientConfig } from "@aws-sdk/client-sts";
2
- import {
3
- fromWebToken as _fromWebToken,
4
- FromWebTokenInit as _FromWebTokenInit,
5
- } from "@aws-sdk/credential-provider-web-identity";
6
- import { CredentialProvider } from "@aws-sdk/types";
7
-
8
- export interface FromWebTokenInit extends _FromWebTokenInit {
9
- clientConfig?: STSClientConfig;
10
- }
11
-
12
- /**
13
- * Creates a credential provider function that gets credentials calling STS
14
- * AssumeRoleWithWebIdentity API.
15
- *
16
- * ```javascript
17
- * import { fromWebToken } from "@aws-sdk/credential-providers"; // ES6 import
18
- * // const { fromWebToken } = require("@aws-sdk/credential-providers"); // CommonJS import
19
- *
20
- * const dynamodb = new DynamoDBClient({
21
- * region,
22
- * credentials: fromWebToken({
23
- * // Required. ARN of the role that the caller is assuming.
24
- * roleArn: "arn:aws:iam::1234567890:role/RoleA",
25
- * // Required. The OAuth 2.0 access token or OpenID Connect ID token that is provided by the identity provider.
26
- * webIdentityToken: await openIdProvider()
27
- * // Optional. Custom STS client configurations overriding the default ones.
28
- * clientConfig: { region }
29
- * // Optional. A function that assumes a role with web identity and returns a promise fulfilled with credentials for
30
- * // the assumed role.
31
- * roleAssumerWithWebIdentity,
32
- * // Optional. An identifier for the assumed role session.
33
- * roleSessionName: "session_123",
34
- * // Optional. The fully qualified host component of the domain name of the identity provider.
35
- * providerId: "graph.facebook.com",
36
- * // Optional. ARNs of the IAM managed policies that you want to use as managed session.
37
- * policyArns: [{arn: "arn:aws:iam::1234567890:policy/SomePolicy"}],
38
- * // Optional. An IAM policy in JSON format that you want to use as an inline session policy.
39
- * policy: "JSON_STRING",
40
- * // Optional. The duration, in seconds, of the role session. Default to 3600.
41
- * durationSeconds: 7200
42
- * }),
43
- * });
44
- * ```
45
- */
46
- export const fromWebToken = (init: FromWebTokenInit): CredentialProvider =>
47
- _fromWebToken({
48
- ...init,
49
- roleAssumerWithWebIdentity:
50
- init.roleAssumerWithWebIdentity ?? getDefaultRoleAssumerWithWebIdentity(init.clientConfig),
51
- });
package/tsconfig.cjs.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "declarationDir": "./dist/types",
4
- "rootDir": "./src",
5
- "outDir": "./dist/cjs",
6
- "baseUrl": "."
7
- },
8
- "extends": "../../tsconfig.cjs.json",
9
- "include": ["src/"]
10
- }
package/tsconfig.es.json DELETED
@@ -1,11 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "lib": ["es5", "es2015.promise", "es2015.collection"],
4
- "declarationDir": "./dist/types",
5
- "rootDir": "./src",
6
- "outDir": "./dist/es",
7
- "baseUrl": "."
8
- },
9
- "extends": "../../tsconfig.es.json",
10
- "include": ["src/"]
11
- }