Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Connect to CRM Using Authentication token provided to authenticate Azure function.

Posted on by 3,115

Hi All

I'm not very sure if it is the correct forum to discuss this or not.. but thought it might still be relevant to CRM and so posting here.

I have an Azure function which requires AAD Authentication to access. My users can use the Client ID & Secret to connect to this function and call it. Inside the function, I need to authenticate to CRM and do some CRUD Actions. For better security, I have to use the same user credentials to connect to CRM as well. Now, I can't really ask the user to pass on the credentials along with the function params was wondering if there is any way to use the same authentication token passed to function headers and generate the CRM service using it? Does any one tried this before? 

I have tried this but I'm getting 

The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Bearer authorization_uri=login.microsoftonline.com/.../authorize, resource_id=https://mydevcrm.api.crm4.dynamics.com/'
On one hand I'm feeling the error is still correct coz' my user actually authenticate to Azure function rather than CRM and so the token will have reference only to Azure functions but on the other hand I'm also wondering coz it is the same Azure AD at the end the user authenticated against and the function also has delegated permissions to CRM.
Any one any idea/suggestions on how to avoid authentication to CRM inside Azure function?
Thank you
-Srikanth
  • ansrikanth Profile Picture
    ansrikanth 3,115 on at
    RE: Connect to CRM Using Authentication token provided to authenticate Azure function.

    Hi

    Sorry, I didn't understand this. Are you asking me to refer any specific part if the links you shared? Coz one of them is talking about CORS and SpA and the other is xrmtooling wpf client both of them are no where close to azure functions... Did I missed anything? Should I be looking in to a specific point in these links?

    Thanks

    -Srikanth

  • Suggested answer
    tcardoso Profile Picture
    tcardoso 137 on at
    RE: Connect to CRM Using Authentication token provided to authenticate Azure function.
    [quote user="ansrikanth"]

    Hi All

    I'm not very sure if it is the correct forum to discuss this or not.. but thought it might still be relevant to CRM and so posting here.

    I have an Azure function which requires AAD Authentication to access. My users can use the Client ID & Secret to connect to this function and call it. Inside the function, I need to authenticate to CRM and do some CRUD Actions. For better security, I have to use the same user credentials to connect to CRM as well. Now, I can't really ask the user to pass on the credentials along with the function params was wondering if there is any way to use the same authentication token passed to function headers and generate the CRM service using it? Does any one tried this before? 

    I have tried this but I'm getting 

    The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Bearer authorization_uri=login.microsoftonline.com/.../authorize, resource_id=https://mydevcrm.api.crm4.dynamics.com/'
    On one hand I'm feeling the error is still correct coz' my user actually authenticate to Azure function rather than CRM and so the token will have reference only to Azure functions but on the other hand I'm also wondering coz it is the same Azure AD at the end the user authenticated against and the function also has delegated permissions to CRM.
    Any one any idea/suggestions on how to avoid authentication to CRM inside Azure function?
    Thank you
    -Srikanth
    [/quote]

    I recommend to you consume this content https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/oauth-cross-origin-resource-sharing-connect-single-page-application adn additional content https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/xrm-tooling/sample-quick-start-xrm-tooling-api

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,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans