代码之家  ›  专栏  ›  技术社区  ›  Mark Micallef

在Dynamics 365的Aquire身份验证令牌上出现错误AADSTS90002

  •  1
  • Mark Micallef  · 技术社区  · 6 年前

    尝试从.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 回复  |  直到 6 年前
        1
  •  1
  •   Arun Vinoth PrecogTechnologies    6 年前

    几点:

    1. 组织URL应该看起来像 https://yourcrm.dynamics.com . Read 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);
    
                    .
    
                    .
                 }
    
        }