简体   繁体   中英

Authentication to Azure Active Directory and receive AADSTS90019 error

I am trying to authenticate against AAD using the following code:

 string userName = "something.com"; //(just an example)
 string password = "IafksdfkasdaFadad=asdad=a="; //(just an example)
 string clientId = "6cd6590f-4db9-4c6b-98d1-476f9e90912f"; //(just an example)
 var credentials = new UserPasswordCredential(userName, password);
 var authenticationContext = new AuthenticationContext("https://login.windows.net/common");
 var result = await authenticationContext.AcquireTokenAsync("https://api.partnercenter.microsoft.com", clientId, credentials);
 return result;

and I got AADSTS90019 error: No tenant-identifying information found in either the request or implied by any provided credentials.

As a remark, it is just a console application made in Visual Studio using C#.

Based on the information from https://docs.microsoft.com/en-us/azure/active-directory/develop/reference-aadsts-error-codes the explication for AADSTS90019 error is: MissingTenantRealm - Azure AD was unable to determine the tenant identifier from the request .

So, my question is: What is the tentant identifier and how should I use it in my request? Should it be the one from the following screenshot? The screenshot is made from the Azure account.

Azure Application Overview

Any information can help.

Thank you.

You should initialize your authentication context with a tenant-specific authority instead of common:

var authenticationContext = new AuthenticationContext("https://login.microsoftonline.com/your-directory-id");

Replace your-directory-id with your Directory (tenant) id.

var authenticationContext = new AuthenticationContext("https://login.windows.net/common");

Here Replace the string "common" with the tenant name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM