dotnet / dotnet/aspnetcore

Expose BearerAndApplicationScheme and CompositeIdentityHandler.

Open
#49,957 5 comments 0 reactions 0 assignees View on GitHub
api-suggestion area-identity enhancement
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

## Background and Motivation

The .NET 8 preview introduces 2 items I'd like to discuss:

1. [IdentityConstants.BearerAndApplicationScheme](https://github.com/dotnet/aspnetcore/blob/main/src/Identity/Core/src/IdentityConstants.cs#L26)
2. [CompositeIdentityHandler](https://github.com/dotnet/aspnetcore/blob/main/src/Identity/Core/src/IdentityServiceCollectionExtensions.cs#L187)

These 2 are used together for IdentityBuilder#AddIdentityApiEndpoints to reduce friction when adding bearer token & cookie auth support to APIs.

## Proposed API

It'd be wonderful if these could be publicly exposed to give even greater flexibility for APIs that don't want to go "all in" on identity's new API endpoints, but do want these to support both bearer tokens & cookies.

```diff
namespace Microsoft.AspNetCore.Identity;

public class IdentityConstants
{
+ public static readonly BearerAndApplicationScheme = IdentityPrefix + ".BearerAndApplication";
}
```

CompositeIdentityHandler would be moved to a publicly visible class

## Usage Examples

The new endpoints are "all or nothing" which is not ideal. Implementations may want only parts of the functionality as well as be able to customize endpoint paths. The above proposal gives a very simple starting point to add functionality they want until this functionality becomes more customizable.

## Alternative Designs

### Alternative 1

An even better long term solution would allow for a configuration option to be passed to IdentityBuilder#AddApiEndpoints method for greater flexibility.

### Alternative 2

Separate the configuration of the AddAuthentication logic into it's own function that is called inside of AddApiEndpoints.

## Risks

These are new items in .NET 8 and exposing them publicly makes them more challenging to deprecate/modify later on.

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.