microsoft-identity-web
microsoft-identity-web copied to clipboard
Be able to use .AddMicrosoftIdentityConsentHandler() without Blazor (was: No account or login hint was passed to the AcquireTokenSilent call - in authorization filter when calling downstream API in a n - tier ASP.Net Core Application)
Which version of Microsoft Identity Web are you using? Microsoft Identity Web 1.10.0
Where is the issue?
- Web app
- [ ] Sign-in users and call web APIs
Is this a new or an existing app?
c. This is a new app or an experiment.
Repro
[AuthorizeForScopes(ScopeKeySection = "DownstreamApi:Scopes")]
public async Task<List> GetListAsync()
{
var apiResult = "";
try
{
using var response = await _downstreamWebApi.CallWebApiForUserAsync("DownstreamApi").ConfigureAwait(false);
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
apiResult = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
}
else
{
var error = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
throw new HttpRequestException($"Invalid status code in the HttpResponseMessage: {response.StatusCode}: {error}");
}
}
catch (MsalUiRequiredException ex)
{
throw ex;
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
Expected behavior
The application(using Microsoft.Identity.Web) does the authentication and calls the Downstream API. The code for calling the downstream API being in the Data Layer(a seperate .netcore 3.1 class library project in the same solution as the MVC).
Actual behavior
The applications shows an error as below, "No account or login hint...."
Possible solution
Tried couple of solutions suggested by @jmprieur in the below issue(towards the bottom of the page). https://github.com/Azure-Samples/active-directory-aspnetcore-webapp-openidconnect-v2/issues/281 When I use the below code in Startup.cs it works.
services.AddServerSideBlazor() .AddMicrosoftIdentityConsentHandler();
But I am not using Blazor in my code. So tried the solution @jmprieur suggested , which was to call .AddMicrosoftIdentityConsentHandler() on services. But when I try it I am getting the below error.
Additional context / logs / screenshots Add any other context about the problem here, such as logs and screenshots.
hello team,
any updates on this? i'm faing the same issue, i'm working on asp.net core 3.1 without Blazor and i need a way to handle the Microsoft Identity Consent.
is there a way to do this right now?
Can we upvote this and make it a bigger priority, please?