Can not consue Azure function APIs secured with Azure AD in SharePoint Framework web part

akash 81 Reputation points
2021-01-08T08:57:10.503+00:00

We have crated a azure function and secured it with with Azure AD. I am now trying to consume this azure function API in spfx web part.

I tried below two approaches to consume api, but I am not able to consume it in web part.

  1. const azureFunctionURL = 'azure function url';
    let url = azureFunctionURL + siteurl;
    const orders: ISPHttpClientOptions = {  
      headers: new Headers(),  
      method: "GET",  
      mode: "cors"  
    };  
    
    return context.spHttpClient.get(url, SPHttpClient.configurations.v1, orders)  
    
    .then((response: SPHttpClientResponse) => {
    return response.json();
    })
    .then(jsonResponse => {
    return jsonResponse;
    }) as Promise
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,112 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Amos Wu-MSFT 4,051 Reputation points
    2021-01-11T05:42:32.503+00:00

    This document provides detailed steps on how to call Azure function in SPFX:Consume enterprise APIs secured with Azure AD in SharePoint Framework
    You could refer to this document for troubleshooting, especially the enable CORS section.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. akash 81 Reputation points
    2021-01-11T13:07:33.623+00:00

    I was able to resolve the issue. I had to specifically add "user_impersonation" azure AD app.

    Regards,
    Akash

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.