Reputation: 37
I have an API address which gets data from CRM. When I try to get data from that API by writing this API in the browser's address bar, I face an error 401
which is an authentication error. I have credentials but don't know how to use them in a request.
Upvotes: 1
Views: 2821
Reputation: 2848
I'm assuming you looked at the samples located here: Basic Operations with web API preview
I've also got some sample code on GitHub: CrmWebApiCSharp
Using the ADAL library, authentication would look something like this:
AuthenticationContext authContext =
new AuthenticationContext(_authority, false);
//Prompt for credentials //_authResult = authContext.AcquireToken( // _serviceUrl, _clientId, new Uri(_redirectUrl));
//No prompt for credentials UserCredential credentials = new UserCredential(_username, _password); _authResult = authContext.AcquireToken( _serviceUrl, _clientId, credentials);
Upvotes: 3