Error when retrieving token from sso Token has expired and refresh failed

Working with AWS services often involves authentication using AWS Single Sign-On (SSO). While AWS CLI simplifies this process, you may occasionally encounter the following error:

Error when retrieving token from sso: Token has expired and refresh fa…


This content originally appeared on DEV Community and was authored by Joao Marques

Working with AWS services often involves authentication using AWS Single Sign-On (SSO). While AWS CLI simplifies this process, you may occasionally encounter the following error:

Error when retrieving token from sso: Token has expired and refresh failed

This error indicates that your SSO session token has expired, and AWS CLI couldn't refresh it automatically. Let's explore why this happens and how you can resolve it.

Why Does This Error Occur?

AWS SSO tokens are temporary credentials that expire after a set period, usually defined by your organization's policies. When the token expires, AWS CLI attempts to refresh it. However, if the refresh attempt fails—perhaps due to a network issue, an expired session, or corrupted cached credentials—you'll see this error.

How to Fix It

1 - Re-authenticate with AWS SSO.

The quickest way to resolve this error is to re-authenticate your AWS SSO session. Use the following command:

aws sso login

This command will open your default browser, prompting you to log in and refresh your session token.

2 - Retry Your Original Command

After re-authenticating, retry the command that triggered the error.

3 - Clear Cached Tokens

If re-authentication doesn’t work, your cached SSO tokens might be corrupted. Clear them manually:

delete the folder: ~/.aws/sso/cache/

or execute this if you are lazy:

rm -rf ~/.aws/sso/cache/

4 - Check AWS CLI Version

Older versions of AWS CLI might have issues with SSO token management. Check your AWS CLI version with this command:

aws --version

and analyse if you can update it for the latest.

My view

Running into the "Token has expired and refresh failed" error can be frustrating, especially when you're in the middle of an important task. Luckily, the fix is usually straightforward: re-authenticate your session or clear the cache. Taking a few extra steps, like keeping your AWS CLI updated or automating token management, can help you avoid these interruptions in the future.

Remember, AWS is designed to make things easier, not harder! If you run into this error, don’t panic. Follow the steps outlined here, and you’ll be back on track in no time.


This content originally appeared on DEV Community and was authored by Joao Marques


Print Share Comment Cite Upload Translate Updates
APA

Joao Marques | Sciencx (2024-11-13T12:56:14+00:00) Error when retrieving token from sso Token has expired and refresh failed. Retrieved from https://www.scien.cx/2024/11/13/error-when-retrieving-token-from-sso-token-has-expired-and-refresh-failed/

MLA
" » Error when retrieving token from sso Token has expired and refresh failed." Joao Marques | Sciencx - Wednesday November 13, 2024, https://www.scien.cx/2024/11/13/error-when-retrieving-token-from-sso-token-has-expired-and-refresh-failed/
HARVARD
Joao Marques | Sciencx Wednesday November 13, 2024 » Error when retrieving token from sso Token has expired and refresh failed., viewed ,<https://www.scien.cx/2024/11/13/error-when-retrieving-token-from-sso-token-has-expired-and-refresh-failed/>
VANCOUVER
Joao Marques | Sciencx - » Error when retrieving token from sso Token has expired and refresh failed. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/11/13/error-when-retrieving-token-from-sso-token-has-expired-and-refresh-failed/
CHICAGO
" » Error when retrieving token from sso Token has expired and refresh failed." Joao Marques | Sciencx - Accessed . https://www.scien.cx/2024/11/13/error-when-retrieving-token-from-sso-token-has-expired-and-refresh-failed/
IEEE
" » Error when retrieving token from sso Token has expired and refresh failed." Joao Marques | Sciencx [Online]. Available: https://www.scien.cx/2024/11/13/error-when-retrieving-token-from-sso-token-has-expired-and-refresh-failed/. [Accessed: ]
rf:citation
» Error when retrieving token from sso Token has expired and refresh failed | Joao Marques | Sciencx | https://www.scien.cx/2024/11/13/error-when-retrieving-token-from-sso-token-has-expired-and-refresh-failed/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.