SPFx - 401 Unauthorized calling Azure Function Secured with AAD

Brass Contributor

Hello,

 

I am trying to call a AAD secured Azure Function from SPFx web part and getting 401 unauthorized error. I have followed - https://docs.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/guidance/connect-to-api-secured-with-... and also added my app registration app uri to allowed token audience as mentioned in https://www.vrdmn.com/2018/02/sharepoint-framework-calling-aad.html

 

The SP app principals are approved from the API Management admin center.

 

Any direction would be a great help.

 

Regards,

Vishwa

2 Replies

The issue has been resolved :) 

 

The function signature has been changed to HttpTrigger(AuthorizationLevel.Anonymous) from [HttpTrigger(AuthorizationLevel.Function)

@Vishwanatha Nayak 

 

Hey if you want to keep the level at a function to keep your endpoint more secure then instead of using https://yourapp?code=longstring

 

take the code out and use the 

x-functions-key in the headers with the code placed (longstring in my example) within the HTTP header and the function will work.