web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Authenticate to CRM Web API using ADAL 3.x

(0) ShareShare
ReportReport
Posted on by

All examples that I have found to authenticate to CRM Web API use AcquireToken method, passing resourceUrl, clientId and redirectUrl. We recently updated our Intranet MVC 5 web app to Active Directory Authentication Library (ADAL) 3.10. This version does not have AcquireToken, but uses AcquireTokenAsync method. Unfortunately, there is no AcquireTokenAsync method with these 3 parameters. I need help to figure out what would be the equivalent process to authenticate to the CRM Web API service using the latest version of ADAL.

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at
    Hope this helps

    private static async Task GetTokenSilent() { // Before create AuthenticationContext, check if Authority(OAuthUrl) is available. if (String.IsNullOrEmpty(OAuthUrl)) { bool success = true; try { await DiscoveryAuthority(); } catch (Exception) { // If failed to retireve OAuthUrl, then make success as false success = false; } // If failed to retrieve OAuthUrl, chances are user mistype ServerUrl. if (!success) { await Utility.ShowMessage("OAuth Url retrieve failed. Please check Service URL again."); return; } } if (SignOut) { if (authContext != null) authContext.TokenCache.Clear(); SignOut = false; } // Create AuthenticationContext by using OAuthUrl. if (authContext == null) authContext = new AuthenticationContext(OAuthUrl, false); // Try to acquire token without prompting user first. AuthenticationResult result = await authContext.AcquireTokenSilentAsync(ResourceName, ClientId); // Check the result. if (result != null && result.Status == AuthenticationStatus.Success) { // A token was successfully retrieved. Then store it. StoreToken(result); return; } //Clear AccessToken _xrmProxy.AccessToken = ""; authContext.TokenCache.Clear(); // Trigger an authentication experience and specify that once a token has been obtained the StoreToken method should be called. result = await authContext.AcquireTokenAsync(ResourceName, ClientId, RedirectUri); StoreToken(result); }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans