CORS issue while accessing Azure function from SPFx Webpart

Pushpanjay Umrao 161 Reputation points
2020-11-27T08:38:20.01+00:00

I have created an Azure function that uses CSOM and Graph api to get site owner details. The Azure function is then triggered from a SPFx webpart. I was earlier using admin creds directly in the code for CSOM calls and hardcoded client id and client secret for Graph api. I had also added my tenant url in the 'Allowed Origin' it was working perfectly until now. However due to company policy i had to use 3rd party certificate for csom connection and instead of directly adding Graph api details i used key vault to generate secret and then use it in code. Now the issue started coming. When i run the azure function directly by running the url in browser it now redirects me to Microsoft login page and when enter my creds it shows me the response. Now when i run the url from my spfx webpart it starts giving me cors error as shown in the attached screenshot.
43226-corsissue.png

My understanding is that the azure function is redirecting to Microsoft Login page and that page is causing this error.

I also tried adding https://login.windows.net and https://login.microsoftonline.com in "Allow Origin" of CORS setting of the Azure function. Any idea how can i resolve this issue

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,321 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,737 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Amos Wu-MSFT 4,051 Reputation points
    2020-12-02T09:39:34.213+00:00
    0 comments No comments