I'm trying to authenticate to our online Dynamics CRM to use the available APIs.
The only official documentation on doing this I can find is: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/connect-customer-engagement-web-services-using-oauth this however uses 'AquireToken' which no longer exists in ADAL V3, with it having been replaced with 'AcquireTokenAsync'.
This is my first time dealing with ADAL and trying to authenticate, previously only having dealt with 'HttpWebRequest' custom APIs.
I'm currently just trying to have the code run without any errors, using what is on docs.microsoft.com I've tried changing 'AcquireToken' to 'AcquireTokenAsync'.
public void authenticateToCRM()
{
// TODO Substitute your correct CRM root service address,
string resource = "https://qqqqqqqqq.crm4.dynamics.com";
// TODO Substitute your app registration values that can be obtained after you
// register the app in Active Directory on the Microsoft Azure portal.
string clientId = "******-****-*******-*****-****";
string redirectUrl = "https://qqqqqqqqq.azurewebsites.net";
// Authenticate the registered application with Azure Active Directory.
AuthenticationContext authContext = new AuthenticationContext("https://login.windows.net/common", false);
AuthenticationResult result = authContext.AcquireTokenAsync(resource, clientId, new Uri(redirectUrl));
}
This results in an error for the 'clientId' string variable in 'AcquireToken' the error being...
"Argument 2: cannot convert from 'string' to 'Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredentials"
and error on the 3rd variable 'new Uri(redirectUrl)', of...
"Argument 3: cannot convert from 'System.Uri' to 'Microsoft.IdentityModel.Clients.ActiveDirectory.UserAssertion"
Looking at the documentation for 'AuthenticationContext' Class and the usage of 'AcquireTokenAsync' many have a string as the 2nd argument: https://docs.microsoft.com/en-us/dotnet/api/microsoft.identitymodel.clients.activedirectory.authenticationcontext?view=azure-dotnet
I do not know how to translate the usage for authentication with 'AcquireToken' shown in the ms docs to use with 'AcquireTokenAsync'