8

I have written the following code to acquire token for CRM.

class Program
{
    private const string username = "richa@azuretraining112.onmicrosoft.com";
    private const string password = "Pa$$w0rd";
    private const string serviceURL = "https://azuretraining112.crm8.dynamics.com";
    private const string applicationID = "89a70b76-3a71-481f-8755-a7aa97c59c35";
    private const string redirectURL = "https://localhost1";
    private const string authorityURI = "https://login.microsoftonline.com/1d54ea41-cd25-488f-812c-c078e6114065/oauth2/authorize";
    private static AuthenticationResult authResult = null;


    private static void Main(string[] args)
    {
        var credentials = new UserPasswordCredential(username, password);
        var context = new AuthenticationContext(authorityURI);
        authResult = context.AcquireTokenAsync(serviceURL, applicationID, credentials).Result;
    }
}

But, while running the code, I am getting the following error while trying to get the token using AcquireTokenAsync.

Blockquote

I have added an application user using the application ID : enter image description here

I don't know what I am missing. Please help!

I tried with the solution given in Tenant not authorized, but, nothing worked.

Thanks!

Richa Tibrewal
  • 468
  • 7
  • 26
  • Possible duplicate of [Error AADSTS90002 on aquire authentication token for Dynamics 365](https://stackoverflow.com/questions/53645374/error-aadsts90002-on-aquire-authentication-token-for-dynamics-365) – Arun Vinoth-Precog Tech - MVP Dec 07 '18 at 12:21
  • @ArunVinoth, I tried both the methods mentioned in the given link. None of that seems to work. – Richa Tibrewal Dec 07 '18 at 16:17
  • Did you try removing “oauth2/authorize” in uri. Discussion going on between endpoint & authority confusion: https://github.com/MicrosoftDocs/azure-docs/issues/19593 – Arun Vinoth-Precog Tech - MVP Dec 09 '18 at 18:37
  • I am getting the following : The request body must contain the following parameter: 'client_secret or client_assertion – Richa Tibrewal Dec 10 '18 at 03:24
  • https://stackoverflow.com/questions/53502733/powerbi-aadsts90002-tenant-authorize-not-found/53517438#53517438 i think this ans may help you – rakshith Mar 07 '19 at 07:51

1 Answers1

0

configure this url with port number "https://localhost1:5000" and configure the same "https://localhost1:5000" in reply URL of Azure AD.

Let me know if this works

Mac D'zen
  • 151
  • 11