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 :
Customer experience | Sales, Customer Insights,...
Suggested Answer

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

(0) ShareShare
ReportReport
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
I have the same question (0)
  • Suggested answer
    tcardoso Profile Picture
    137 on at
    [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

  • ansrikanth Profile Picture
    3,115 on at

    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

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 70 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 33 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans