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

Using Identity with JWT Authentication #1376

@dchristensen

Description

@dchristensen

I have an API that is using a ASP.NET Core Identity and JWT tokens. The application is only using the Identity system to manager users (adding, removing and updating passwords & profile data), not to do any kind authentication (that is handled externally). I am now trying to port this application from ASP.NET Core 1.x to 2.0 and running into problems. Prior to 2.0 I could call services.AddIdentity(/* options */) to add all of the required services and not call app.UseIdentity() so that the cookie middleware was not added.

This solution was referenced in an issue awhile ago: aspnet/Security#804

In 2.0 calling services.AddIdentity always adds cookie authentication which then takes over the authentication pipeline and will redirect unauthenticated requests to the login page instead of returning a 401. Even trying to override the cookie authentication by using the following after AddIdentity is called does not work:

        services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, options =>
            {
                options.Audience = "my_aud";
                options.Authority = "my_authority";
            });

Is there anyway to add the Identity management services to the DI container without dragging along the cookie middleware?

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