blazor-samples icon indicating copy to clipboard operation
blazor-samples copied to clipboard

Extra error trapping for Entra BFF sample?

Open guardrex opened this issue 8 months ago • 2 comments

We might want a bit more error trapping ...

https://github.com/dotnet/blazor-samples/blob/main/9.0/BlazorWebAppEntraBff/BlazorWebAppEntra/Program.cs#L153-L155

@halter73 @mikekistler Does adding ReplyForbiddenWithWwwAuthenticateHeaderAsync trapping on MicrosoftIdentityWebChallengeUserException and MsalUiRequiredException make sense to roll into ☝️ of the Entra BFF sample?

Something like ...

string accessToken;

try
{
    accessToken = await tokenAcquisition.GetAccessTokenForUserAsync(
        scopes, user: httpContext.User);
}
catch (MicrosoftIdentityWebChallengeUserException exception)
{
    await tokenAcquisition.ReplyForbiddenWithWwwAuthenticateHeaderAsync(
        exception.Scopes, exception.MsalUiRequiredException, httpContext.Response);
    return;
}
catch (MsalUiRequiredException exception)
{
    await tokenAcquisition.ReplyForbiddenWithWwwAuthenticateHeaderAsync(
        scopes, exception, httpContext.Response);
    return;
}

if (!string.IsNullorEmpty(accessToken))
{
    transformContext.ProxyRequest.Headers.Authorization = new("Bearer", accessToken);
}

Issue Details

Do not edit this section. It is required for issue processing.

guardrex avatar May 07 '25 23:05 guardrex