繁体   English   中英

对 Azure Active Directory 的身份验证并收到 AADSTS90019 错误

[英]Authentication to Azure Active Directory and receive AADSTS90019 error

我正在尝试使用以下代码对 AAD 进行身份验证:

 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;

我收到 AADSTS90019 错误:在请求中或任何提供的凭据中都找不到租户识别信息。

作为备注,它只是在 Visual Studio 中使用 C# 制作的控制台应用程序。

根据来自https://docs.microsoft.com/en-us/azure/active-directory/develop/reference-aadsts-error-codes的信息,AADSTS90019 错误的解释是: MissingTenantRealm - Azure 无法确定 AD请求中的租户标识符

所以,我的问题是:什么是 tentant 标识符,我应该如何在我的请求中使用它? 它应该是以下屏幕截图中的那个吗? 截图来自 Azure 账户。

Azure 应用概述

任何信息都可以提供帮助。

谢谢你。

您应该使用特定于租户的权限而不是通用权限来初始化您的身份验证上下文:

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

your-directory-id替换为您的目录(租户)ID。

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

此处将字符串“common”替换为租户名称。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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