gpt4 book ai didi

c# - 获取 Dynamics 365 的身份验证 token 时出现错误 AADSTS90002

转载 作者:行者123 更新时间:2023-12-02 08:02:13 27 4
gpt4 key购买 nike

尝试从 .Net 客户端使用 Dynamics 365 进行身份验证时遇到以下错误:

AADSTS90002: Tenant authorize not found. This may happen if there are no active subscriptions for the tenant. Check with your subscription administrator.

这是我当前使用的代码:

AuthenticationParameters authenticationParameters = AuthenticationParameters.CreateFromResourceUrlAsync(new Uri("https://dev-aec-ssp.api.crm6.dynamics.com/api/data/v9.1/")).Result;
AuthenticationContext authenticationContext = new AuthenticationContext(authenticationParameters.Authority, false);
ClientCredential clientCredential = new ClientCredential("9cd8fe45-xxxx-xxxx-xxxx-e43ef81c803f", "abcdefghijk");
AuthenticationResult authenticationResult = null;
try
{
authenticationResult = authenticationContext.AcquireTokenAsync("https://dev-aec-ssp.api.crm6.dynamics.com", clientCredential).Result;
}
catch (Exception ex)
{
throw new Exception("Failed to authenticate with remote Dynamics service.", ex);
}

AcquireTokenAsync 总是失败。

最佳答案

几点:

  1. 组织网址应类似于 https://yourcrm.dynamics.comRead more

  2. GitHub issue说:

https://login.microsoftonline.com/{Guid} (where the Guid is the tenant ID
or
https://login.microsoftonline.com/domainName where the domain name is a domain associated with your tenant
or
https://login.microsoftonline.com/common

    string organizationUrl = "https://yourcrm.dynamics.com";
string appKey = "*****";
string aadInstance = "https://login.microsoftonline.com/";
string tenantID = "myTenant.onmicrosoft.com";
string clientId = "UserGUID****";
public Task<String> SendData()
{
return AuthenticateWithCRM();
}

public async Task<String> AuthenticateWithCRM()
{
ClientCredential clientcred = new ClientCredential(clientId, appKey);
AuthenticationContext authenticationContext = new AuthenticationContext(aadInstance + tenantID);
AuthenticationResult authenticationResult = await authenticationContext.AcquireTokenAsync(organizationUrl, clientcred);
using (HttpClient httpClient = new HttpClient())
{
httpClient.BaseAddress = new Uri(organizationUrl);

.

.
}

}

关于c# - 获取 Dynamics 365 的身份验证 token 时出现错误 AADSTS90002,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53645374/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com