Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save emregulcan/d82a564bb977780ab4eb6d04bc23734d to your computer and use it in GitHub Desktop.

Select an option

Save emregulcan/d82a564bb977780ab4eb6d04bc23734d to your computer and use it in GitHub Desktop.
Dynamics 365 CE (CRM) Web API Authentication by using ADAL (Active Directory Authentication Library)
public string RetrieveAuthToken(string authorityURI, string d365Url, string clientId, string clientSecret)
{
string result = string.Empty;
ClientCredential clientCredential = new ClientCredential(clientId, clientSecret);
AuthenticationContext authenticationContext = new AuthenticationContext(authorityURI, false);
var authenticationResult = authenticationContext.AcquireTokenAsync(d365Url, clientCredential).GetAwaiter().GetResult();
result = authenticationResult.AccessToken;
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment