azure-sdk-for-python: DefaultAzureCredential Azure SQL error: VisualStudioCodeCredential The refresh token has expired due to inactivity

  • Package Name: azure-identity
  • Package Version: 1.8.0
  • Operating System: Windows
  • Python Version: 3.9.7

Describe the bug Using DefaultAzureCredential from azure.identity while get_token() gives the following error for certain users: VisualStudioCodeCredential The refresh token has expired due to inactivity

To Reproduce Using the following code: https://docs.sqlalchemy.org/en/14/dialects/mssql.html#connecting-to-databases-with-access-tokens On this line:

raw_token = azure_credentials.get_token(TOKEN_URL).token.encode("utf-16-le")

the error is thrown that the refresh token has expired due to inactivity of greater than 90 days. The code works fine for me, but not for my coworkers. We’ve tried updating all packages and dropping the users from Azure SQL and recreating them. I found this in the documentation (https://docs.microsoft.com/en-us/cli/azure/authenticate-azure-cli) saying

As of August 2018 this token is revoked after 90 days of inactivity, but this value can be changed by Microsoft or your tenant administrator. Once the token is revoked you get a message from the CLI saying you need to login again.

However, I can’t find anywhere in the Azure Portal to renew the token. Also, using DefaultAzureCredential works fine for connecting to blob storage, the error only throws on get_token() on the database.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

Hi @blawrence-datadx , thanks for the feedback. We’ll take a look at this and get back to you asap.