Repository navigation
Reuse valid cached SSO token in aws sso login - #10918
Open
vurumalla92 wants to merge 1 commit into
Open
vurumalla92 wants to merge 1 commit into
vurumalla92 wants to merge 1 commit into
Conversation
Fixes aws#6948: aws sso login forced a fresh login on every invocation by passing force_refresh=True unconditionally, even when a valid token was already cached. The login command now reuses a valid cached SSO access token and prints 'Already logged into Start URL', and accepts --force to retrieve a new token. Adds a cached-token validity helper mirroring botocore's 15-minute expiry window, updated help text, reworked and new unit and functional tests, and a changelog entry.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6948
Problem
aws sso loginforced a fresh login on every invocation:LoginCommandpassedforce_refresh=Trueunconditionally to the SSO token fetcher, even when a valid access token was already cached. Users who runaws sso loginseveral times a day had to re-authenticate in the browser every time, although the cached token was still valid.Fix
aws sso loginnow reuses a valid cached SSO access token and reportsAlready logged into Start URL: <url>instead of starting a new browser login.--forceflag retrieves a new access token even when a valid cached token exists, preserving the previous behavior on demand.get_cached_sso_token()helper inawscli/customizations/sso/utils.pyreads the same token cache botocore's fetchers use and treats a token as expired when it expires within the same 15-minute window botocore uses, so the CLI and botocore agree on validity. Acreate_sso_token_cache()helper centralizes cache creation.aws sso loginhelp text to describe the reuse behavior and--force..changes/next-releaseenhancement entry.Tests
get_cached_sso_token(): valid token (string and datetime expiry), expired token, token expiring within the 15-minute window, missing/invalid token, and SSO-session cache keys.--forcereuses the cached token (no new OIDC calls, browser handler not invoked again); second login with--forcefetches a new token; a seeded expired cached token triggers a fresh login. Covers both the device-code and authorization-code flows.Test results (run locally in this repo checkout):
tests/functional/sso/test_login.py: 49 passed.tests/unit/customizations/sso/test_utils.py(new-helper tests): 26 passed.tests/unit/customizations/sso/+tests/functional/sso/): 203 passed, 3 failed. The 3 failures are pre-existing environmental failures inTestDoSSOLogin(test_do_sso_login,test_do_sso_login_preauthorized,test_do_sso_login_passes_redirect_port_to_auth_code_fetcher): their setup creates a realsso-oidcclient and the sandbox egress proxy refuses the connection (urllib3.exceptions.ProxyError). They fail identically without this change.pip install -e .could not run in this sandbox (the editable build shells out through the same blocked egress proxy), so the package was not installed; tests were run withPYTHONPATHpointing at the repo checkout.ruff checkpasses on all changed files;ruff formatpasses on the changed source files (two pre-existing format nits in the test files were left untouched).Generated by AI tools, and reviewed by Venkateshwar Reddy Vurumalla.