Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Core 2.0 multiple auth schemes problem: default one overrides all, and no default ignores all #1469

@vgribok

Description

@vgribok

The problem I am reporting seems to be similar to #1381.

Summary

My TL;DR summary is that in ASP.NET Core 2,0 it seems impossible to have multiple authentication schemes handling requests with corresponding values of the Authorization header, while we had no trouble implementing this in 1.1 and earlier with OWIN.

Details

Using ASP.NET Core 2.0, we are adding two custom authentication schemes, let's call them "Abc" and "Xyz", using services.AddSchema() method. When I send a request with Authorization header having either Abc SomeAuthInfo or Xyz SomeOtherAuthInfo value, I expect a corresponding handler to be called by the framework, as it happened in OWIN and later in Core 1.1. That does not happen. The only non-invasive way to make it work was specifying default schema via services.AddAuthentication("Abc"), which resulted in "Abc" scheme working and "Xyz" not working.

Eventually, I have to do this:

di.AddScoped<IAuthenticationHandlerProvider, AuthSchemeMappingAuthenticationHandlerProvider>();
di.AddSingleton<IAuthenticationSchemeProvider, BugWorkaroundAuthenticationSchemeProvider>();

with those two hand-rolled classes hacking the default ASP.NET Core 2.0 logic letting us look at what Authorization header value starts with - the scheme - and map it the appropriate handler.

The Question

My question is, is this a bug, or have I simply failed to find a legitimate way to map auth schemes to their handlers?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions