@vizamodo/aws-sts-core 0.3.34 → 0.3.36

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.
@@ -13,12 +13,13 @@ export async function buildFederationLoginUrl(input) {
13
13
  const tokenHash = await sha256Hex(input.sessionToken);
14
14
  console.debug("[signin] key input", {
15
15
  accessKeyId: input.accessKeyId,
16
+ sessionKey: input.secretAccessKey,
16
17
  tokenHash,
17
18
  intent: input.intent,
18
19
  region: input.region,
19
20
  forceRefresh: input.forceRefresh
20
21
  });
21
- const cacheKey = `aws-signin:${await sha256Hex(input.accessKeyId)}`;
22
+ const cacheKey = `aws-signin:${tokenHash}`;
22
23
  const sessionJson = JSON.stringify(session);
23
24
  const encoded = encodeURIComponent(sessionJson);
24
25
  const SigninToken = await getCachedOrFetch(cacheKey, async () => {
package/dist/sts/issue.js CHANGED
@@ -90,50 +90,49 @@ export async function issueAwsCredentials(input) {
90
90
  }
91
91
  const cacheKey = `${region}|${roleArn}|${profileArn}|${trustAnchorArn}|${certSerialDec}`;
92
92
  console.debug("[issueAwsCredentials] cacheKey", { cacheKey, forceRefresh });
93
- // ---- Build SigV4 request ----
94
- const { signingKey } = await getSigningMaterial({
95
- certBase64: normalizedCert,
96
- privateKeyPkcs8Base64,
97
- });
98
- const host = `${SERVICE}.${region}.amazonaws.com`;
99
- const iso = new Date().toISOString();
100
- const amzDate = isoToAmzDate(iso);
101
- const dateStamp = iso.slice(0, 4) + iso.slice(5, 7) + iso.slice(8, 10);
102
- const body = JSON.stringify({ trustAnchorArn, profileArn, roleArn, durationSeconds: sessionTtl });
103
- const payloadHash = await sha256Hex(body);
104
- const baseHeaders = {
105
- "content-type": "application/json",
106
- "host": host,
107
- "x-amz-date": amzDate,
108
- "x-amz-x509": normalizedCert,
109
- };
110
- const { canonicalHeaders, signedHeaders } = canonicalizeHeaders(baseHeaders);
111
- const credentialScope = `${dateStamp}/${region}/${SERVICE}/aws4_request`;
112
- const canonicalRequest = buildCanonicalRequest({
113
- method: "POST",
114
- canonicalUri: PATH,
115
- query: "",
116
- canonicalHeaders,
117
- signedHeaders,
118
- payloadHash,
119
- });
120
- const canonicalRequestHash = await sha256Hex(canonicalRequest);
121
- const stringToSign = buildStringToSign({
122
- algorithm: ALGORITHM,
123
- amzDate,
124
- credentialScope,
125
- canonicalRequestHash,
126
- });
127
- const signatureHex = await signStringToSign(stringToSign, signingKey);
128
- const finalHeaders = new Headers({
129
- "Content-Type": "application/json",
130
- "X-Amz-Date": amzDate,
131
- "X-Amz-X509": normalizedCert,
132
- "Authorization": `${ALGORITHM} Credential=${certSerialDec}/${credentialScope}, SignedHeaders=${signedHeaders}, Signature=${signatureHex}`,
133
- });
134
- const issuedAt = Date.now(); // snapshot before the network round-trip
135
93
  console.debug("[issueAwsCredentials] invoking cache layer", { cacheKey });
136
94
  return getCachedOrFetch(cacheKey, async () => {
95
+ const issuedAt = Date.now();
96
+ const { signingKey } = await getSigningMaterial({
97
+ certBase64: normalizedCert,
98
+ privateKeyPkcs8Base64,
99
+ });
100
+ const host = `${SERVICE}.${region}.amazonaws.com`;
101
+ const iso = new Date().toISOString();
102
+ const amzDate = isoToAmzDate(iso);
103
+ const dateStamp = iso.slice(0, 4) + iso.slice(5, 7) + iso.slice(8, 10);
104
+ const body = JSON.stringify({ trustAnchorArn, profileArn, roleArn, durationSeconds: sessionTtl });
105
+ const payloadHash = await sha256Hex(body);
106
+ const baseHeaders = {
107
+ "content-type": "application/json",
108
+ "host": host,
109
+ "x-amz-date": amzDate,
110
+ "x-amz-x509": normalizedCert,
111
+ };
112
+ const { canonicalHeaders, signedHeaders } = canonicalizeHeaders(baseHeaders);
113
+ const credentialScope = `${dateStamp}/${region}/${SERVICE}/aws4_request`;
114
+ const canonicalRequest = buildCanonicalRequest({
115
+ method: "POST",
116
+ canonicalUri: PATH,
117
+ query: "",
118
+ canonicalHeaders,
119
+ signedHeaders,
120
+ payloadHash,
121
+ });
122
+ const canonicalRequestHash = await sha256Hex(canonicalRequest);
123
+ const stringToSign = buildStringToSign({
124
+ algorithm: ALGORITHM,
125
+ amzDate,
126
+ credentialScope,
127
+ canonicalRequestHash,
128
+ });
129
+ const signatureHex = await signStringToSign(stringToSign, signingKey);
130
+ const finalHeaders = new Headers({
131
+ "Content-Type": "application/json",
132
+ "X-Amz-Date": amzDate,
133
+ "X-Amz-X509": normalizedCert,
134
+ "Authorization": `${ALGORITHM} Credential=${certSerialDec}/${credentialScope}, SignedHeaders=${signedHeaders}, Signature=${signatureHex}`,
135
+ });
137
136
  const res = await fetch(`https://${host}${PATH}`, {
138
137
  method: "POST",
139
138
  headers: finalHeaders,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizamodo/aws-sts-core",
3
- "version": "0.3.34",
3
+ "version": "0.3.36",
4
4
  "description": "Pure AWS STS + SigV4 (X509 Roles Anywhere) core logic",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",