I have a SPA that uses Azure AD B2C and MSAL libraries. SPA is part of a ASP.Net Core Angular Application. So, the application has .Net Controller that connects to the other azure hosted Web APIs. When angular code makes a HTTP call to the controller, MSAL interceptor kicks in and sends the token across. But, when I try to get the token in the controller using tokenAcquisition.GetAccessTokenForUserAsync, I get error.
fail: Microsoft.Identity.Web.TokenAcquisition[0]
Microsoft.Identity.Web.TokenAcquisition: Error: False MSAL 4.54.1.0 MSAL.NetCore .NET 7.0.4 Darwin 22.1.0 Darwin Kernel Version 22.1.0: Sun Oct 9 20:14:54 PDT 2022; root:xnu-8792.41.9~2/RELEASE_X86_64 [2023-06-10 05:37:32Z - 867a5621-fbcc-4cd4-8533-692ba502c3de] Exception type: Microsoft.Identity.Client.MsalUiRequiredException
, ErrorCode: user_null
HTTP StatusCode 0
Can someone please advise what I am doing wrong here?
I have followed this code sample on GitHub
Expectation: When Azure AD B2C user logs in in the SPA and the SPA makes a HTTP call to the .net controller, the controller should be able to acquire the token to pass it to downstream Web API.