Skip to content

Extra error trapping for Entra BFF sample? #535

Description

@guardrex

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

EnhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions