Sample on how to call remote API from SPFx web part. Uses ASP.NET Core 2.1 as backend API (Azure AD authentication) and cookie authentication from SPFx side (xhr "with credentials")
How to use
- Create new app regisration in Azure AD. Copy Client Id and your TenantId (can be found in Azure Portal under App Registrations - > Endpoints, copy guid from any endpoint). In reply url specify
https://localhost:44361/(for local debugging, after deployment add your real site url) web app folder contains ASP.NET code.
web app\WebApp-OpenIDConnect-DotNet.slnin Visual Studio 2017 (15.7 minimum)
ClientIdto match your configuration
Ctrl + F5to run web app. Try to open
https://localhost:44361/- you should be redirected to your organization login page.
- Under spfx folder run
- Add Hello World web part to local workbench and observe console - data from Web API should be available.