【问题标题】:Error AADSTS90002 on aquire authentication token for Dynamics 365获取 Dynamics 365 的身份验证令牌时出现错误 AADSTS90002
【发布时间】:2019-05-07 19:03:35
【问题描述】:

尝试从我的 .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 总是失败。

【问题讨论】:

    标签: c# azure dynamics-crm adal dynamics-crm-online


    【解决方案1】:

    几个点:

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

    2. GitHub issue 说:

    https://login.microsoftonline.com/{Guid}(其中 Guid 是租户 ID

    https://login.microsoftonline.com/domainName,其中域名是与您的租户关联的域

    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);
    
                    .
    
                    .
                 }
    
        }
    

    【讨论】:

    • 嗨阿伦。我相信这可能已经解决了这个问题。我现在正在运行一些测试。感谢您的帮助!
    • @MarkMicallef 很高兴听到
    • 所以,我正在通过 AuthenticationContext 上的 AcquireTokenAsync() 方法,这是我之前遇到的问题。但是,当发送 HttpClient 上的 SendAsync() 请求时,我得到了 Unauthorized 回复。我已经检查并且授权标头中有一个 Bearer 令牌,所以我不确定我现在缺少什么。
    猜你喜欢
    • 2017-07-01
    • 2013-12-04
    • 2015-06-01
    • 2016-06-04
    • 2016-12-07
    • 2015-04-05
    • 1970-01-01
    • 2023-02-10
    • 1970-01-01
    相关资源
    最近更新 更多