@vizamodo/aws-sts-core 0.3.25 → 0.3.27
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/dist/federation/login.js +20 -4
- package/package.json +1 -1
package/dist/federation/login.js
CHANGED
|
@@ -15,15 +15,31 @@ export async function buildFederationLoginUrl(input) {
|
|
|
15
15
|
const encoded = encodeURIComponent(sessionJson);
|
|
16
16
|
const SigninToken = await getCachedOrFetch(cacheKey, async () => {
|
|
17
17
|
const tokenResp = await fetch(`https://signin.aws.amazon.com/federation?Action=getSigninToken&Session=${encoded}`);
|
|
18
|
+
if (!tokenResp.ok) {
|
|
19
|
+
// best-effort: skip cache, let caller retry upstream if needed
|
|
20
|
+
return "";
|
|
21
|
+
}
|
|
18
22
|
const json = await tokenResp.json();
|
|
19
|
-
const token = json
|
|
20
|
-
if (!token)
|
|
21
|
-
|
|
23
|
+
const token = json?.SigninToken;
|
|
24
|
+
if (!token) {
|
|
25
|
+
// best-effort: skip cache
|
|
26
|
+
return "";
|
|
27
|
+
}
|
|
22
28
|
// SigninToken TTL ~15 minutes (AWS behavior)
|
|
23
29
|
const SIGNIN_TOKEN_TTL_SEC = 15 * 60;
|
|
24
|
-
|
|
30
|
+
// derive effective TTL = min(tokenTTL, credentialTTL)
|
|
31
|
+
const credRemainingSec = Math.floor((Date.parse(input.expiration) - Date.now()) / 1000);
|
|
32
|
+
const effectiveTtlSec = Math.min(SIGNIN_TOKEN_TTL_SEC, credRemainingSec);
|
|
33
|
+
// if credential too close to expiry → skip caching
|
|
34
|
+
if (effectiveTtlSec <= 0) {
|
|
35
|
+
return token;
|
|
36
|
+
}
|
|
37
|
+
return wrapResult(token, new Date(Date.now() + effectiveTtlSec * 1000).toISOString());
|
|
25
38
|
}, { ttlSec: 60 } // fallback only if expiration invalid
|
|
26
39
|
);
|
|
40
|
+
if (!SigninToken) {
|
|
41
|
+
throw new Error("[federation] unable to obtain SigninToken");
|
|
42
|
+
}
|
|
27
43
|
const baseLogin = `https://signin.aws.amazon.com/federation?Action=login` +
|
|
28
44
|
`&Issuer=viza` +
|
|
29
45
|
`&SigninToken=${SigninToken}`;
|