Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How we can create universal OAuth App

Posted on by Microsoft Employee

Hello,

I am working on developing an integration with Dynamics CRM and using OAuth for authentication. I have created a OAuth App in Azure and with that I am able to generate "access_token" which is required to access the APIs. I have developed and tested application with this and everything is working fine.

Now I am planning to move my app to beta in which other users could try my app out. I have hardcoded "client_id", "client_secret" and "redirect_URI" in my app. When people are trying to authenticate, the authorize URL getting formed something like this -

https://login.windows.net/common/oauth2/authorize?response_type=code&client_id=<MY_APPS_CLIENT_ID>&redirect_uri=<MY_APPS_REDIRECT_URI>&scope=user_impersonation&resource=<MY_CUSTOMERS_CRM_INSTANCE_URL>

Here MY_CUSTOMERS_CRM_INSTANCE_URL is something like https://XXXX.crm8.dynamics.com

with the above URL I am getting the code. I am using that code to do a POST call on https://login.windows.net/common/oauth2/token to generate the access token. The tokens calls is also working fine and I am getting the "access_toke", "refresh_token", "resource" in response. here the resource returned in response is MY_CUSTOMERS_INSTANCE_URI which they have entered while initiating authentication.

The problem I am facing is when I am trying to use this API to fetch the "Contacts" or "Accounts" from Customer's CRM instance. My API call is something like this -

https://XXXX.crm8.dynamics.com/api/data/v8.2/accounts/

and in headers I am passing

Authorization: Bearer <ACCESS_TOKEN_RECIEVED_IN_TOKENS_CALL_RESPONSE>

HTTP Error 401 - Unauthorized: Access is denied

All the calls made above are from a NODE_APPLICATION developed by me.

I have earlier worked on OAuth for other applications(e.g. Box.com) and there using the similar flow, I was able to make the API calls. Please suggest if anything I am missing.

*This post is locked for comments

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans