Skip to content

Commit eeb08f4

Browse files
committed
fix(credential-provider-ini): pass clientConfig to sso and sso-oidc inner clients
1 parent 0982bc4 commit eeb08f4

File tree

8 files changed

+31
-25
lines changed

8 files changed

+31
-25
lines changed

packages/credential-provider-ini/src/fromIni.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ export interface FromIniInit extends SourceProfileInit, CredentialProviderOption
3939
roleAssumerWithWebIdentity?: (params: AssumeRoleWithWebIdentityParams) => Promise<AwsCredentialIdentity>;
4040

4141
/**
42-
* STSClientConfig to be used for creating STS Client for assuming role.
42+
* STSClientConfig or SSOClientConfig to be used for creating inner client
43+
* for auth operations.
4344
* @internal
4445
*/
4546
clientConfig?: any;

packages/credential-provider-ini/src/resolveSsoCredentials.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
import { setCredentialFeature } from "@aws-sdk/core/client";
22
import type { SsoProfile } from "@aws-sdk/credential-provider-sso";
3-
import type { CredentialProviderOptions } from "@aws-sdk/types";
43
import type { IniSection, Profile } from "@smithy/types";
54

5+
import type { FromIniInit } from "./fromIni";
6+
67
/**
78
* @internal
89
*/
9-
export const resolveSsoCredentials = async (
10-
profile: string,
11-
profileData: IniSection,
12-
options: CredentialProviderOptions = {}
13-
) => {
10+
export const resolveSsoCredentials = async (profile: string, profileData: IniSection, options: FromIniInit = {}) => {
1411
const { fromSSO } = await import("@aws-sdk/credential-provider-sso");
1512
return fromSSO({
1613
profile,
1714
logger: options.logger,
15+
parentClientConfig: options.parentClientConfig,
16+
clientConfig: options.clientConfig,
1817
})().then((creds) => {
1918
if (profileData.sso_session) {
2019
return setCredentialFeature(creds, "CREDENTIALS_PROFILE_SSO", "r");

packages/credential-provider-sso/src/fromSSO.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export const fromSSO =
133133
ssoRoleName: sso_role_name,
134134
ssoClient: ssoClient,
135135
clientConfig: init.clientConfig,
136+
parentClientConfig: init.parentClientConfig,
136137
profile: profileName,
137138
});
138139
} else if (!ssoStartUrl || !ssoAccountId || !ssoRegion || !ssoRoleName) {
@@ -150,6 +151,7 @@ export const fromSSO =
150151
ssoRoleName,
151152
ssoClient,
152153
clientConfig: init.clientConfig,
154+
parentClientConfig: init.parentClientConfig,
153155
profile: profileName,
154156
});
155157
}

packages/credential-provider-sso/src/resolveSSOCredentials.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const resolveSSOCredentials = async ({
2020
ssoRoleName,
2121
ssoClient,
2222
clientConfig,
23+
parentClientConfig,
2324
profile,
2425
logger,
2526
}: FromSSOInit & SsoCredentialsParameters): Promise<AwsCredentialIdentity> => {
@@ -65,6 +66,7 @@ export const resolveSSOCredentials = async ({
6566
ssoClient ||
6667
new SSOClient(
6768
Object.assign({}, clientConfig ?? {}, {
69+
logger: clientConfig?.logger ?? parentClientConfig?.logger,
6870
region: clientConfig?.region ?? ssoRegion,
6971
})
7072
);

packages/token-providers/src/fromSso.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ describe(fromSso.name, () => {
4848
accessToken: "mockNewAccessToken",
4949
expiresIn: 3600,
5050
refreshToken: "mockNewRefreshToken",
51+
$metadata: {},
5152
};
5253
const mockNewToken = {
5354
token: mockNewTokenFromService.accessToken,

packages/token-providers/src/fromSso.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ import { writeSSOTokenToFile } from "./writeSSOTokenToFile";
2020
*/
2121
const lastRefreshAttemptTime = new Date(0);
2222

23-
export interface FromSsoInit extends SourceProfileInit, CredentialProviderOptions {}
23+
export interface FromSsoInit extends SourceProfileInit, CredentialProviderOptions {
24+
/**
25+
* @see SSOOIDCClientConfig in \@aws-sdk/client-sso-oidc.
26+
*/
27+
clientConfig?: any;
28+
}
2429

2530
/**
2631
* Creates a token provider that will read from SSO token cache or ssoOidc.createToken() call.
@@ -101,7 +106,7 @@ export const fromSso =
101106

102107
try {
103108
lastRefreshAttemptTime.setTime(Date.now());
104-
const newSsoOidcToken = await getNewSsoOidcToken(ssoToken, ssoRegion);
109+
const newSsoOidcToken = await getNewSsoOidcToken(ssoToken, ssoRegion, init);
105110
validateTokenKey("accessToken", newSsoOidcToken.accessToken);
106111
validateTokenKey("expiresIn", newSsoOidcToken.expiresIn);
107112
const newTokenExpiration = new Date(Date.now() + newSsoOidcToken.expiresIn! * 1000);

packages/token-providers/src/getNewSsoOidcToken.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { SSOToken } from "@smithy/shared-ini-file-loader";
22

3+
import { FromSsoInit } from "./fromSso";
34
import { getSsoOidcClient } from "./getSsoOidcClient";
45

56
/**
67
* Returns a new SSO OIDC token from ssoOids.createToken() API call.
78
* @internal
89
*/
9-
export const getNewSsoOidcToken = async (ssoToken: SSOToken, ssoRegion: string) => {
10+
export const getNewSsoOidcToken = async (ssoToken: SSOToken, ssoRegion: string, init: FromSsoInit = {}) => {
1011
// @ts-ignore Cannot find module '@aws-sdk/client-sso-oidc'
1112
const { CreateTokenCommand } = await import("@aws-sdk/client-sso-oidc");
1213

13-
const ssoOidcClient = await getSsoOidcClient(ssoRegion);
14+
const ssoOidcClient = await getSsoOidcClient(ssoRegion, init);
1415
return ssoOidcClient.send(
1516
new CreateTokenCommand({
1617
clientId: ssoToken.clientId,
Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
1-
const ssoOidcClientsHash: Record<string, any> = {};
1+
import { FromSsoInit } from "./fromSso";
22

33
/**
4-
* Returns a SSOOIDC client for the given region. If the client has already been created,
5-
* it will be returned from the hash.
4+
* Returns a SSOOIDC client for the given region.
65
* @internal
76
*/
8-
export const getSsoOidcClient = async (ssoRegion: string) => {
7+
export const getSsoOidcClient = async (ssoRegion: string, init: FromSsoInit = {}) => {
98
// @ts-ignore Cannot find module '@aws-sdk/client-sso-oidc'
109
const { SSOOIDCClient } = await import("@aws-sdk/client-sso-oidc");
1110

12-
// return ssoOidsClient if already created.
13-
if (ssoOidcClientsHash[ssoRegion]) {
14-
return ssoOidcClientsHash[ssoRegion];
15-
}
16-
17-
// Create new SSOOIDC client, and store is in hash.
18-
// If we need to support configuration of SsoOidc client in future through code,
19-
// the provision to pass region from client configuration needs to be added.
20-
const ssoOidcClient = new SSOOIDCClient({ region: ssoRegion });
21-
ssoOidcClientsHash[ssoRegion] = ssoOidcClient;
11+
const ssoOidcClient = new SSOOIDCClient(
12+
Object.assign({}, init.clientConfig ?? {}, {
13+
region: ssoRegion ?? init.clientConfig.region,
14+
logger: init.clientConfig?.logger ?? init.parentClientConfig?.logger,
15+
})
16+
);
2217
return ssoOidcClient;
2318
};

0 commit comments

Comments
 (0)