-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] Blazor server does not handle the MsalUiRequiredException #360
Comments
@gwgrubbs @schmid37 @using Microsoft.Identity.Web
@inject AuthenticationStateProvider AuthenticationStateProvider
@inject NavigationManager NavigationManager and then in protected override async Task OnInitializedAsync()
{
try
{
apiResult = await downstreamAPI.CallWebApiAsync();
}
catch (MicrosoftIdentityWebChallengeUserException ex)
{
await BlazorHelper.ChallengeUserAsync(
ex,
AuthenticationStateProvider,
NavigationManager,
GetType().Name).ConfigureAwait(false);
}
} Here's an example. We might take this as a "quick fix", with a better long term solution. Let us know if this works for you. Thanks. cc: @jmprieur |
@jennyf19 What I did: protected override async Task OnInitializedAsync()
{
try
{
retVal = await AadService.GetAsync();
}
catch (MicrosoftIdentityWebChallengeUserException ex)
{
await BlazorHelper.ChallengeUserAsync(
ex,
AuthenticationStateProvider,
NavigationManager,
GetType().Name).ConfigureAwait(false);
}
} Exception: blazor.server.js:19 [2020-07-24T12:48:31.731Z] Error: System.NullReferenceException: Object reference not set to an instance of an object. |
thanks @schmid37 @gwgrubbs @inject MicrosoftIdentityConsentAndConditionalAccessHandler ConsentHandler;
...
@code {
private string apiResult;
protected override async Task OnInitializedAsync()
{
try
{
apiResult = await downstreamAPI.CallWebApiAsync();
}
catch (Exception ex)
{
ConsentHandler.HandleException(ex);
}
} And then in services.AddServerSideBlazor()
.AddMicrosoftIdentityConsentHandler(); Appreciate your patience as we sort this out. |
First login works. Error: System.NullReferenceException: Object reference not set to an instance of an object. --> Delete cookies, and it works again. |
@jennyf19 so what I want to say, after a server restart, it never works. |
Case where a cookie exists, but the token does not exist in cache and an attempt to acquire a new token (running locally). in _Host.cshtml: @model _HostAuthPageModel method in _HostAuthPageModel.cs: public async Task<IActionResult> OnGet()
{
if (!User.Identity.IsAuthenticated)
return Challenge();
try
{
AccessToken = await tokenAcquisition.GetAccessTokenForUserAsync(apiOptions.Value.Scopes);
}
catch (MicrosoftIdentityWebChallengeUserException ex)
{
//can't get a token from the token store, MUST assume a sign-out path as requests to API will NOT be authenticated
logger.LogError(ex, ex.Message);
consentHandler.HandleException(ex);
}
return Page();
} So, at initial page load of the application the
|
Thank you @gwgrubbs @schmid37 I'm not able to reproduce this. Do you have a basic repro you can share w/exact steps? That will help determine a fix faster. Thank you. You can email it if you want too: [email protected] |
@jennyf19 Thank you for the help. I emailed you! |
@gwgrubbs @schmid37 This is included in Microsoft Identity Web 0.2.1-preview release. |
@gwgrubbs @schmid37 |
When calling Blazor server for the acquire token silent (or OBO) part, or when there is a need for more scopes or conditional access, Blazor does not handle
context.Result = new ChallengeResult(properties);
in AuthorizeForScopesAttribute, like in MVC or Razor.The text was updated successfully, but these errors were encountered: