1

Goodnight,

I have a site in Sharepoint 2019 with a webpart spfx and I have a site where a web api runs with the business logic. The api has Windows authentication

From SharePoint I can connect to the web api using the following in the http request:

JavaScript code:

this.context.spHttpClient.get('http://custom-api:1011/controller', {}, { headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, credentials: 'include' })

I tried with spHttpClient and httpClient

From the web api, I need to connect to sharepoint with the credentials of the current user and perform some actions, but it always generates error 401

C# code:

var handler = new HttpClientHandler {UseDefaultCredentials = true}; HttpClient = new HttpClient (handler); HttpResponseMessage response = await client.GetAsync ($"{SiteUrl}/_api/web/SiteGroups");

In summary I need to make the following jumps.

SharePoint SPFX => External Web Api => SharePoint api REST.

with spHttpClient the error was {"odata.error":{"code":"-2147024891, System.UnauthorizedAccessException","message":{"lang":"en-US","value":"Access denied. You do not have permission to perform this action or access this resource."}}}

The test user is an administrator of the site collection

Thank you

1
  • Hello did you find a solution? I have the same issue but using spfx with react Commented Jul 26, 2023 at 17:13

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.