dotnet / dotnet/aspnetcore

Add new event to OpenIdConnectEvents to handle specific error scenario

Open
#63,566 1 comment 0 reactions 0 assignees View on GitHub
api-suggestion area-auth
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

## Background and Motivation

In reference to https://github.com/dotnet/aspnetcore/issues/59462, there is a new scenario during OIDC PAR login flow where a configuration would result in an error. The optimal solution would be to add a new OIDC event to the API to make it easier to handle this error.

## Proposed API

In reference to https://github.com/dotnet/aspnetcore/pull/61947, add new event to `OpenIdConnectEvents` class. Event name would be `OnPushAuthorizationFailed`.

## Usage Examples

Example originally documented in https://github.com/dotnet/aspnetcore/pull/61947

```csharp
builder.Services.AddAuthentication(...)
.AddOpenIdConnect("oidc", options =>
{
...
options.Events.OnPushAuthorizationFailed = (ctx) => {
var logger = ctx.HttpContext.RequestServices.GetRequiredService>();
logger.LogError(ctx.Exception, "Received error while sending PAR request.");

ctx.Response.Redirect("FriendlyErrorPage");
ctx.Handled = true;
return Task.CompletedTask;
};
});
```

## Alternative Designs

No. I attempted to follow the existing API event design.

## Risks

No exceptional risks identified.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.