I am using MSAL for JavaScript in a react app to authenticate against Azure AD. I am able to successfully authenticate user and get id token and access token. But the retrieved access token cannot access the API that is secured with Azure AD.
Everything is configured find on Azure AD side as I can use the retrieved access token to talk to the API using a dotnet core web app.
The difference between dotnet core app and react app is the "resource" attribute. I am not sure how to include that in the request with MSAL.
My React Code:
userAgentApplication = new UserAgentApplication(
"<clientid>",
"<azureAdUrl>",
this.authCallback,
{ redirectUri: "http://localhost:3000/", cacheLocation: "localStorage" }
);
authCallback(errorDesc, token, error, tokenType) {
if (token) console.log(token);
}
login() {
this.userAgentApplication.loginRedirect().then(function(idToken) {
this.userAgentApplication.acquireTokenSilent().then(
function(accessToken) {
console.log('Access Token: ' + accessToken);
}
);
});
}
With a dotnet core app, I am using same configurations as both URL's configured in Azure AD app with one addition.
.AddOpenIdConnect(o =>
{
....
o.Resource = "GUID of the API";
});
I am not sending this resource parameter with MSAL.Not sure how to send that and if that is that is the problem.
Any help is appreciated.