Consume enterprise APIs secured with Azure AD in SharePoint Framework

Justin Jia 306 Reputation points
2021-03-10T06:47:28.06+00:00

i want to connect to an enterprise API secured with Azure Active Directory from a SharePoint Framework
here is the docs
https://learn.microsoft.com/en-us/sharepoint/dev/spfx/use-aadhttpclient-enterpriseapi
when everything is done, i can access the azure function api from the sp webpart, .

then i create a new asp.net core web service and use microsoft.identity.web for authentication
https://github.com/AzureAD/microsoft-identity-web/wiki/web-apis
but when access from the sp webpart, the result is 302 (redirct to the https://login.microsoftonline.com)
i can find the authorization header and the JWT is correct

so did I miss something?

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,826 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,706 questions
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,577 questions
0 comments No comments
{count} votes

Accepted answer
  1. MichaelHan-MSFT 18,016 Reputation points
    2021-03-11T08:08:49.89+00:00

    Hello anonymous user,

    Looks like this issue is not related with sharepoint spfx. I think it could be the authentication in your web API.

    You could refer to below articles to configure the authentication:

    https://www.reddit.com/user/azzurrabrancati/comments/f1r3op/consume_azure_ad_secured_web_api_net_core_31_from/

    https://www.c-sharpcorner.com/article/create-an-asp-net-core-api-with-azure-ad-authentication-and-consuming-it-in-spfx/

    Third-party contact disclaimer:
    Microsoft provides third-party contact information to help you find technical support. This contact information may change without notice. Microsoft does not guarantee the accuracy of this third-party contact information.


    If an Answer 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.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Justin Jia 306 Reputation points
    2021-03-15T04:50:26.733+00:00

    hi @MichaelHan-MSFT thanks for your response. you are totally right. And i can finish the demo by following the articles. But my existing project is Asp.net core 3.1 with microsoft-identity-web https://github.com/AzureAD/microsoft-identity-web/wiki/Mixing-web-app-and-web-api-in-the-same-ASP.NET-core-app so i append the demo code to my project, but it doesn't work. ![77651-16157837636817.png][1] [1]: /api/attachments/77651-16157837636817.png?platform=QnA