Why can't I re-authenticate (MFA with mssql extension for VS Code)?

1.4k views Asked by At

Here's an example of a connection configuration that has stopped working (it's for connecting to an Azure managed database):

{
  "server": "sqldb.12345abcde.database.windows.net",
  "database": "sqldb01",
  "authenticationType": "AzureMFA",
  "profileName": "sqldb01",
  "azureAccountToken": "",
  "expiresOn": 1648022420,
  "email": "[email protected]",
  "accountId": "aaaaaaaa-0000-bbbb-1111-cccccc222222"
}

When I try to connect, VS Code displays a dialog saying mssql: Credential Error: Account credentials have expired. Please re-authenticate. and another saying mssql: undefined:

VS Code dialog screenshot

After clicking the refresh credentials button, the linked page fails to resolve in my browser, showing ERR_CONNECTION_REFUSED:

ERR_CONNECTION_REFUSED browser screenshot

When I reinstall the plugin, remove my connection definitions from settings.json and attempt to create a new connection, the browser page resolves correctly and allows me to authenticate, but it has no effect in VS Code.

I'm able use the same connection details in Azure Data Studio to connect successfully.

3

There are 3 answers

0
benmcf On BEST ANSWER

I resolved this by deleting the contents of this folder (Mac): ~/Library/Application Support/vscode-mssql/AAD.

I believe the equivalent on Windows would be something like C:\Users\{username}\AppData\Roaming\vscode-mssql\Azure Accounts.

1
Scott C. On

I had the same/similar problem and found 2 possible issues in my case. I went into Windows Credential Manager and Removed the aad-iv and aad-key credentials, as well as all the others that did not say Modified: Today (presumably overkill).

When I then tried again in VSCode, I received an error but was able to proceed by it giving me a chance to enter credentials. In my case, it then failed to connect with an option to automatically add a firewall rule... and then everything worked.

I'm not sure if it wasn't smart enough to figure out how to refresh credentials OR if it was trying to but something with the firewall rule came into the picture and disrupted it.

After this, I noticed Windows Credential Manager had aad-iv and aad-key credentials added back. So... I would try removing just those 2 and see what happens.

0
LPB On

I did the same as benmcf. However, I also deleted the AAD folder:
C:\Users\{user}\AppData\Roaming\vscode-mssql\AAD

After it, I uninstalled the MSSQL extension and installed again. Then it worked.