Error AADSTS90002 on aquire authentication token for Dynamics 365

后端 未结 1 1495
悲&欢浪女
悲&欢浪女 2021-01-26 00:16

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

AADSTS90002: Tenant authorize not found. This may ha         


        
1条回答
  •  隐瞒了意图╮
    2021-01-26 00:46

    Couple of points:

    1. The Org url should look like https://yourcrm.dynamics.com. Read more

    2. The GitHub issue says:

    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 SendData()
        {
            return AuthenticateWithCRM();
        }
    
        public async Task 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);
    
                    .
    
                    .
                 }
    
        }
    

    0 讨论(0)
提交回复
热议问题