1

I have been trying to create an Azure Function using the documentation. For example, here: https://learn.microsoft.com/en-us/learn/modules/develop-azure-functions/5-create-function-visual-studio-code

Every time, and with every Azure account, I can't get past the step where you sign in to your Azure account from the Azure Functions VSCode extension. This is the error I am getting:

"Selected user account does not exist in tenant 'Microsoft Learn Sandbox' and cannot access the application 'aebc6443-996d-45c2-90f0-388ff96faa56' in that tenant. The account needs to be added as an external user in the tenant first. Please use a different account."

The Microsoft Learn Sandbox error message is a red herring to me, as I am not trying to do anything with it, only with Azure Functions. The same error appears even with a completely different Azure account.

I have tried looking at several possible solutions, including switching directories (but I only have one directory, so this didn't work), changing settings in Azure AD Connect (but I don't have Azure AD Connect configured, so this didn't work), and I deleted several local .config files and directories on my machine (CentOS 7, btw). If the solution is related to my .config files, I couldn't tell which files I should actually be deleting though.

Alma Eyre
  • 23
  • 1
  • 4
  • Have you ever had an account in this tenant before? Maybe try this and just log out of everything: https://login.microsoftonline.com/common/oauth2/v2.0/logout – Nick.Mc Jan 16 '22 at 22:05
  • This is the error that I get when I try that: "Sorry, but we’re having trouble signing you out. AADSTS90002: Tenant '987721d9-5527-4002-b351-1bd7ffc827e5' not found. Check to make sure you have the correct tenant ID and are signing into the correct cloud. Check with your subscription administrator, this may happen if there are no active subscriptions for the tenant." When I go to the Portal I am still signed in. Signing out from the Portal gives me the same error. – Alma Eyre Jan 17 '22 at 01:22

2 Answers2

1

In my situation, the problem is it was trying to use my "learning" account but I wanted to use my "work" account.

Following the answer here: https://learn.microsoft.com/en-us/answers/questions/696758/how-do-i-sign-in-to-azure-from-vs-code?page=1&orderby=Helpful&comment=answer-697695#newest-answer-comment

  • Go to the Azure portal and sign out (https://portal.azure.com/) Now open Visual Studio and Open the Command Palette (Ctrl + Shift + P)
  • search for Azure: Sign Out and click on it. It will signout you from the Visual Studio extension
  • Then (this is the important part) it allowed me the option to Clear my Tenant ID.
  • Then you can sign in again with the new account

Hope this helps someone else!

Justin
  • 1,303
  • 15
  • 30
0

Selected user account does not exist in tenant 'Microsoft Learn Sandbox' and cannot access the application 'aebc6443-996d-45c2-90f0-388ff96faa56' in that tenant.

Few of the workarounds you can try to sign in to Azure successfully are:

Solution 1:

Try Signing in using the CLI/PowerShell Terminals from VS Code: enter image description here

1. CLI:

Thanks to @AkashYellappa as this is one of the workarounds to login to the Azure:


1. List all the subscriptions you have

    az account list --output table
    
      Name             CloudName     SubscriptionId     State     IsDefault
    ---------------   ------------  ----------------  ---------  ----------
    AssociateProd      AzureCloud    xxxxxxxxxxxx       Enabled    False

2. Pick the subscription you want and use it in the command below.

    az account set --subscription <subscription_id>
az login --tenant-id <tenant-id>

Note: To get tenant-id, Go to Azure Portal > Azure Active Directory > Copy the Tenant Id.

2. PowerShell:

`Connect-AzAccount -Subscription <subscription_Name>`
or
`Connect-AzAccount -Tenant <String>`

After selecting the correct tenant/directory, you can check to see if the user does exist in that directory by going to:

Azure Active Directory -> Users -> All Users -> Search for the user

Solution 2:

As mentioned the VS developer community, this is expected behavior because something needs access to a resource in that tenant.

  • If you have MFA setup, sign in to that tenant with the correct MFA.
  • If you do not have any MFA setup, then remove yourself from that tenant and sign-in again.

For more information, Please follow steps provided in this Microsoft documentation.

Solution 3:

  1. Open VS Code > Open the Command Palette (Ctrl + Shift P) > Type Preferences: User Settings and Click on it.
  2. Type Azure in the search bar, it will show the settings of Azure Resources and Select Azure Configuration.

enter image description here

Include your tenant id by clicking on the Edit settings.json option or on the below box provided named as Azure:Tenant.

  1. Save the user settings (JSON) and use Ctrl+Shift+P once again. Select Azure: Sign in. The authentication page loads in your browser. Sign in to your endpoint.

  2. To test that you have successfully logged into your Azure subscription, use Ctrl+Shift+ P and select Azure: Select Subscription and see if the subscription you have is available.

For more information, please refer this Microsoft documentation.

Note: Here your account is Microsoft Learn Sandbox, not the Work/School account. Sometimes this kind of error occurs due to endpoint set to for authorization. Please refer this SO Thread for more information on signing is different between the "Personal Microsoft" accounts and "Work/School" accounts.