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 Web Api On-Premise using adfs

(0) ShareShare
ReportReport
Posted on by

I want to authenticate CRM2016 On-Premise (also I m using adfs), not crm online. I m coding crm webapi utility page for my project. I tried to authenticate webapi by 3 ways ;

1-  Nothing happens after this code;

HttpClient client = new HttpClient(new HttpClientHandler() { Credentials = new NetworkCredential(userName, password, domainName) });
client.BaseAddress = new Uri("https://crm2016demo.xxxxxx.net:444/");
client.Timeout = new TimeSpan(0, 2, 0);

client.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0");
client.DefaultRequestHeaders.Add("OData-Version", "4.0");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

  HttpResponseMessage retrieveResponse = await client.GetAsync("api/data/v8.0/accounts(A2A0FC09-DBBE-E511-80E2-005056B000B7)");

 

2 - I gave the service url and user credentials as shown below. I m getting 404 error in this line ;  return authContext.AcquireToken .

ps: I tried username without giving domainname.

public string ServiceUrl = "crm2016demo.xxxxxxx.net";

public string Authority= "crm2016demo.xxxxxxx.net/main.aspx";


var authContext = new AuthenticationContext(Authority, false);

UserCredential credentials = new UserCredential(Domain + @"\" + UserName, Password);
return authContext.AcquireToken(ServiceUrl, ClientId, credentials);


3 - Also I tried to authenticate with this code (as shown below). When I run the code, Crm online authentication window is opened. Then I wrote username and password, this window shows the crm page with small size. But I want to authenticate crm, I don't need crm page.


var Authority = "crm2016demo.xxxxxxx.net/main.aspx";

var authContext = new AuthenticationContext(Authority, false);

return authContext.AcquireToken(
ServiceUrl, ClientId, new Uri(RedirectUrl));

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Maarten Hamburg Profile Picture
    on at

    If you use the SDK, there are templates for this purpose. You only have to add the Credentials.xml in you roaming profile folder crm. This is the easies way to use authentication for online and on-premise. These can be found in the helpercode folder

  • Community Member Profile Picture
    on at

    Thank you for your answer. But I can't access the crm server. And I cant find it int the sdk 2016 on premise.

    I'm getting Authority Uri from DiscoveryAuthority method. Method returns this uri =https://stsdemo2016.xxxx.net/adfs/oauth2/authorize/

    When I give this uri to get AuthenticationContext , AcquireTokenAsync gives this error ;

    Microsoft.IdentityModel.Clients.ActiveDirectory.AdalException: This method overload is not supported by
    =https://stsdemo2016.xxxx.net/adfs/oauth2/authorize/

  • howexg9 Profile Picture
    45 on at

    Do you have any solutions for this? I have same question for this.

    Thanks.

  • Community Member Profile Picture
    on at

    I'm having the exact same question. It seems like a simple thing to send GET/POST requests to the Web API On Premise. After all, simply surfing to the end-point in the browser works wonderfully. But I cannot seem to authenticate in PowerShell/Node/PostMan etc. How do I accomplish this?

  • Community Member Profile Picture
    on at

    Same critical situation here, Please let me know if someone have solution for this.

    Thanks in Advance

  • Community Member Profile Picture
    on at

    I have same issue trying to discover the authority url at run time, but only for CRM 2016 (8.1) On-Premise using ADFS and IFD.

    D365 Online works fine.

    I am beginning to wonder if you can actually call the CRM web api services for CRM 2016 (8.1) On-Premise using ADFS and IFD.

    AuthenticationParameters ap = AuthenticationParameters.CreateFromResourceUrlAsync(
                            new Uri("mydomain.crm.dynamics.com/.../data")).Result;

    String authorityUrl = ap.Authority;
    String resourceUrl  = ap.Resource;

    Error that I get is;

    Invalid authenticate header format
    Parameter name: authenticateHeader

    Can anyone assist please?

  • Jeff2 Profile Picture
    on at

    I have this same issue. Same error. Same on-prem installation (ours is "on prem 365").

  • slx Profile Picture
    386 on at

    Hi,

    I am having the same issue. Any luck with any feedback ?

    Thank you

  • Nicksoft Profile Picture
    205 on at

    Can Any one Help providing samples or instructions on How to Utilize CRM On-premise WebAPI on external Single Page applications?? However i tried single page application with javascript ADAL.js for online following below article.

    docs.microsoft.com/.../walkthrough-registering-configuring-simplespa-application-adal-js

    But for On-Premise, this seems to not work. Any one can provide any insights on this issue??

  • sarcia Profile Picture
    5 on at

    Did you find a way to authenticate using other clients like Postman??

    As you I'm able to use the endpoints in the browser once I have log-in to the CRM.

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