Skip to content

Commit

Permalink
fix(credential-provider-sso): accept all unexpired tokens as unexpired (
Browse files Browse the repository at this point in the history
  • Loading branch information
kellertk committed Aug 22, 2023
1 parent 6af11f7 commit b57d48f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@ describe(resolveSSOCredentials.name, () => {
const mockExpiredToken = { ...mockToken, expiresAt: new Date(Date.now() - 60 * 1000).toISOString() };
(getSSOTokenFromFile as jest.Mock).mockResolvedValue(mockExpiredToken);
});

it("throws error if SSO session expires in <15 mins", async () => {
const mockExpiredToken = { ...mockToken, expiresAt: new Date(Date.now() + 899 * 1000).toISOString() };
(getSSOTokenFromFile as jest.Mock).mockResolvedValue(mockExpiredToken);
});
});

describe("throws error on sso.getRoleCredentials call", () => {
Expand Down
10 changes: 1 addition & 9 deletions packages/credential-provider-sso/src/resolveSSOCredentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ import { AwsCredentialIdentity } from "@smithy/types";

import { FromSSOInit, SsoCredentialsParameters } from "./fromSSO";

/**
* The time window (15 mins) that SDK will treat the SSO token expires in before the defined expiration date in token.
* This is needed because server side may have invalidated the token before the defined expiration date.
*
* @internal
*/
const EXPIRE_WINDOW_MS = 15 * 60 * 1000;

const SHOULD_FAIL_CREDENTIAL_CHAIN = false;

/**
Expand Down Expand Up @@ -52,7 +44,7 @@ export const resolveSSOCredentials = async ({
}
}

if (new Date(token.expiresAt).getTime() - Date.now() <= EXPIRE_WINDOW_MS) {
if (new Date(token.expiresAt).getTime() - Date.now() <= 0) {
throw new CredentialsProviderError(
`The SSO session associated with this profile has expired. ${refreshMessage}`,
SHOULD_FAIL_CREDENTIAL_CHAIN
Expand Down

0 comments on commit b57d48f

Please sign in to comment.