Skip to content

Reuse valid cached SSO token in aws sso login - #10918

Open
vurumalla92 wants to merge 1 commit into
aws:v2from
vurumalla92:fix-sso-login-respect-expiration-6948
Open

vurumalla92 wants to merge 1 commit into
aws:v2from
vurumalla92:fix-sso-login-respect-expiration-6948

Conversation

@vurumalla92

Copy link
Copy Markdown

Fixes #6948

Problem

aws sso login forced a fresh login on every invocation: LoginCommand passed force_refresh=True unconditionally to the SSO token fetcher, even when a valid access token was already cached. Users who run aws sso login several times a day had to re-authenticate in the browser every time, although the cached token was still valid.

Fix

  • aws sso login now reuses a valid cached SSO access token and reports Already logged into Start URL: <url> instead of starting a new browser login.
  • New --force flag retrieves a new access token even when a valid cached token exists, preserving the previous behavior on demand.
  • New get_cached_sso_token() helper in awscli/customizations/sso/utils.py reads 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. A create_sso_token_cache() helper centralizes cache creation.
  • Updated aws sso login help text to describe the reuse behavior and --force.
  • Added a .changes/next-release enhancement entry.

Tests

  • New unit tests for 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.
  • Reworked functional login tests: second login without --force reuses the cached token (no new OIDC calls, browser handler not invoked again); second login with --force fetches 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.
  • Full SSO suite (tests/unit/customizations/sso/ + tests/functional/sso/): 203 passed, 3 failed. The 3 failures are pre-existing environmental failures in TestDoSSOLogin (test_do_sso_login, test_do_sso_login_preauthorized, test_do_sso_login_passes_redirect_port_to_auth_code_fetcher): their setup creates a real sso-oidc client 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 with PYTHONPATH pointing at the repo checkout.
  • ruff check passes on all changed files; ruff format passes 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.

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.
@vurumalla92
vurumalla92 requested a review from a team as a code owner November 18, 2026 15:23

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

aws sso login should respect credential expiration

1 participant