365的获取身份验证令牌的错误AADSTS90002

365的获取身份验证令牌的错误AADSTS90002

本文介绍了有关Dynamics 365的获取身份验证令牌的错误AADSTS90002的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am encountering the following error when attempting to authenticate with Dynamics 365 from my .Net client:

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

这是我当前使用的代码:

Here is the code I am currently using:

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上总是失败。

It always fails on AcquireTokenAsync.

推荐答案

点对:


  1. 组织URL应该看起来像 https://yourcrm.dynamics.com

说:





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

                .

                .
             }

    }

这篇关于有关Dynamics 365的获取身份验证令牌的错误AADSTS90002的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 09:40