Hi @ RekellCaraan-3504,
Thanks for the update.
I have tried to replicate the issue by registering web app and web api and expose the scope of API in web app and able to call the web API successfully from web APP in .NET core.
I tried multiple combinations to reproduce the error at my end, but I am able to sign in the B2C application and calling web API successfully after providing credentials.
The error you are getting might be due to incorrect configurations in the application.
I am trying to understand the use case where web App is calling itself for webAPI. The scope of webAPI need to expose for which client applications can obtain access tokens and call webAPI from web app. In case of single registered application, webapp calling the application itself.
Are you also facing this issue when you are registering the two applications separately for both web application and web API?
The scope you are passing in configuration file does not seem to be correct. It should be redirected to API scope with its address. Below is the configuration file I am using for which i am able to call web API successfully.
{
"AzureAdB2C": {
"Instance": "https://tenant.b2clogin.com",
"ClientId": "xxxx-xxx-xx-xx-xx",
"Domain": "tenant.onmicrosoft.com",
"SignedOutCallbackPath": "/B2C_1_signupsignin//oauth2/v2.0/logout/",
"SignUpSignInPolicyId": "B2C_1_signupsignin",
"ClientSecret": "xxx"
},
"API": {
"APIScope": "https://tenant.onmicrosoft.com/my-api/access_as_user",
"APIBaseAddress": "https://localhost:44332"
},
In startup. cs
services.AddMicrosoftIdentityWebAppAuthentication(Configuration, Constants.AzureAdB2C)
.EnableTokenAcquisitionToCallDownstreamApi(new string[] { Configuration["API:APIScope"] })
.AddInMemoryTokenCaches();
I refer https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/tree/master/4-WebApp-your-API/4-2-B2C to call webApp from webAPI.
Note: Posting it as answer as comment has limit restriction.