Currently, I am working on a .Net Web App. After going through the authentication process with Azure AD B2C using the Azure AD Connect protocol, my app's controller successfully obtains an access token via the MSAL library (written in C# code) to connect to a backend Web API. Everything works smoothly up to this point. Now, I need to figure out how to utilize this access token obtained from the server-side C# code in my client-side JavaScript within the same web app to access the Web API without being prompted to sign-in again.
To kick things off, I utilized sample code available on GitHub which helped get me started with the process. However, when I run my JavaScript code, it throws an error stating: "user_login_error:User
login is required".
if (!clientApplication) {
clientApplication = new Msal.UserAgentApplication(window.config.clientID, window.config.authority, authCallback);
clientApplication.redirectUri = window.config.redirectUri;
}
function ReloadInfo(type, language, location) {
clientApplication.acquireTokenSilent(window.config.b2cScopes).then(function (accessToken) {
ReadResource(accessToken, type, language, location);
}, function (error) {
clientApplication.acquireTokenPopup(window.config.b2cScopes).then(function (accessToken) {
ReadResource(accessToken, type, language, location);
}, function (error) {
debugger
logMessage("Error acquiring the access token to call the Web api:\n" + error);
});
})
}
Any insights or help regarding this matter will be greatly appreciated! Thank you!