Skip to content

Commit ba1b145

Browse files
authored
fix(token-providers): use static version of bundled sso oidc client (#5067)
1 parent f86ff34 commit ba1b145

File tree

11 files changed

+2224
-25
lines changed

11 files changed

+2224
-25
lines changed

packages/token-providers/README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type is going to be token based. For example, the `bearer` authorization type se
1010
## Static Token Provider
1111

1212
```ts
13-
import { fromStatic } from "@aws-sdk/token-providers"
13+
import { fromStatic } from "@aws-sdk/token-providers";
1414

1515
const token = { token: "TOKEN" };
1616
const staticTokenProvider = fromStatic(token);
@@ -21,7 +21,7 @@ const staticToken = await staticTokenProvider(); // returns { token: "TOKEN" }
2121
## SSO Token Provider
2222

2323
```ts
24-
import { fromSso } from "@aws-sdk/token-providers"
24+
import { fromSso } from "@aws-sdk/token-providers";
2525

2626
// returns token from SSO token cache or ssoOidc.createToken() call.
2727
const ssoToken = await fromSso();
@@ -30,10 +30,24 @@ const ssoToken = await fromSso();
3030
## Token Provider Chain
3131

3232
```ts
33-
import { nodeProvider } from "@aws-sdk/token-providers"
33+
import { nodeProvider } from "@aws-sdk/token-providers";
3434

3535
// returns token from default providers.
3636
const token = await nodeProvider();
3737
```
3838

3939
[http-bearer-auth-trait]: https://smithy.io/2.0/spec/authentication-traits.html#smithy-api-httpbearerauth-trait
40+
41+
---
42+
43+
### Development
44+
45+
This package contains a minimal copy of the SSO OIDC client, instead of relying on the full client, which
46+
would cause a circular dependency.
47+
48+
When regenerating the bundled version of the SSO OIDC client, run the esbuild.js script and then make the following changes:
49+
50+
- Remove any dependency of the generated client on the credential chain such that it would create
51+
a circular dependency back to this package. Because we only need the `CreateTokenCommand`, the client, and this command's
52+
associated `Exception`s, it is possible to remove auth dependencies.
53+
- Ensure all required packages are declared in the `package.json` of token-providers.

packages/token-providers/package.json

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"module": "./dist-es/index.js",
77
"sideEffects": false,
88
"scripts": {
9-
"build:client-dist": "node ./scripts/esbuild",
10-
"build": "yarn build:client-dist && concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
9+
"build:client-bundle": "node ./scripts/esbuild",
10+
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
1111
"build:cjs": "tsc -p tsconfig.cjs.json",
1212
"build:es": "tsc -p tsconfig.es.json",
1313
"build:include:deps": "lerna run --scope $npm_package_name --include-dependencies build",
@@ -27,11 +27,41 @@
2727
},
2828
"license": "Apache-2.0",
2929
"dependencies": {
30+
"@aws-crypto/sha256-browser": "3.0.0",
31+
"@aws-crypto/sha256-js": "3.0.0",
32+
"@aws-sdk/middleware-host-header": "*",
33+
"@aws-sdk/middleware-logger": "*",
34+
"@aws-sdk/middleware-recursion-detection": "*",
35+
"@aws-sdk/middleware-user-agent": "*",
3036
"@aws-sdk/types": "*",
31-
"@smithy/property-provider": "^2.0.0",
32-
"@smithy/shared-ini-file-loader": "^2.0.0",
37+
"@aws-sdk/util-endpoints": "*",
38+
"@aws-sdk/util-user-agent-browser": "*",
39+
"@aws-sdk/util-user-agent-node": "*",
40+
"@smithy/config-resolver": "^2.0.2",
41+
"@smithy/fetch-http-handler": "^2.0.2",
42+
"@smithy/hash-node": "^2.0.2",
43+
"@smithy/invalid-dependency": "^2.0.2",
44+
"@smithy/middleware-content-length": "^2.0.2",
45+
"@smithy/middleware-endpoint": "^2.0.2",
46+
"@smithy/middleware-retry": "^2.0.2",
47+
"@smithy/middleware-serde": "^2.0.2",
48+
"@smithy/middleware-stack": "^2.0.0",
49+
"@smithy/node-config-provider": "^2.0.2",
50+
"@smithy/node-http-handler": "^2.0.2",
51+
"@smithy/protocol-http": "^2.0.2",
52+
"@smithy/smithy-client": "^2.0.2",
3353
"@smithy/types": "^2.1.0",
34-
"tslib": "^2.5.0"
54+
"@smithy/url-parser": "^2.0.2",
55+
"@smithy/util-base64": "^2.0.0",
56+
"@smithy/util-body-length-browser": "^2.0.0",
57+
"@smithy/util-body-length-node": "^2.0.0",
58+
"@smithy/util-defaults-mode-browser": "^2.0.2",
59+
"@smithy/util-defaults-mode-node": "^2.0.2",
60+
"@smithy/util-retry": "^2.0.0",
61+
"@smithy/util-utf8": "^2.0.0",
62+
"tslib": "^2.5.0",
63+
"@smithy/property-provider": "^2.0.0",
64+
"@smithy/shared-ini-file-loader": "^2.0.0"
3565
},
3666
"devDependencies": {
3767
"@tsconfig/recommended": "1.0.1",
@@ -57,10 +87,10 @@
5787
"dist-*/**"
5888
],
5989
"browser": {
60-
"./dist-es/client-sso-oidc-bundle/dist-node": "./dist-es/client-sso-oidc-bundle/dist-browser"
90+
"./dist-es/bundle/client-sso-oidc-node": "./dist-es/bundle/client-sso-oidc-browser"
6191
},
6292
"react-native": {
63-
"./dist-es/client-sso-oidc-bundle/dist-node": "./dist-es/client-sso-oidc-bundle/dist-browser"
93+
"./dist-es/bundle/client-sso-oidc-node": "./dist-es/bundle/client-sso-oidc-browser"
6494
},
6595
"homepage": "https://github.com/aws/aws-sdk-js-v3/tree/main/packages/token-providers",
6696
"repository": {

packages/token-providers/scripts/esbuild.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ const root = path.join(__dirname, "..", "..", "..");
2121
const browserRuntimeConfig = fs.readFileSync(
2222
path.join(path.dirname(defaultRuntimeConfigFile), "runtimeConfig.browser.ts")
2323
);
24+
const clientPkgJsonPath = path.join(root, "clients", "client-sso-oidc", "package.json");
25+
const clientPkgJson = require(clientPkgJsonPath);
26+
fs.writeFileSync(
27+
clientPkgJsonPath,
28+
JSON.stringify({
29+
version: clientPkgJson.version,
30+
})
31+
);
2432

2533
for (const platform of ["browser", "node"]) {
2634
if (platform === "browser") {
@@ -29,14 +37,7 @@ const root = path.join(__dirname, "..", "..", "..");
2937
fs.writeFileSync(defaultRuntimeConfigFile, nodeRuntimeConfig);
3038
}
3139

32-
const outfile = path.join(
33-
root,
34-
"packages",
35-
"token-providers",
36-
"src",
37-
"client-sso-oidc-bundle",
38-
`dist-${platform}.ts`
39-
);
40+
const outfile = path.join(root, "packages", "token-providers", "src", "bundle", `client-sso-oidc-${platform}.ts`);
4041

4142
await esbuild.build({
4243
platform,
@@ -54,4 +55,5 @@ const root = path.join(__dirname, "..", "..", "..");
5455
}
5556

5657
fs.writeFileSync(defaultRuntimeConfigFile, nodeRuntimeConfig);
58+
fs.writeFileSync(clientPkgJsonPath, JSON.stringify(clientPkgJson, null, 2) + "\n");
5759
})();

0 commit comments

Comments
 (0)