0

I am trying to get the [Authroize] tag working on .NET Core 2.1 Web API project built on .NET Framework. There is no IAppBuilder.UseAuthorization(). I wrote my own JWT custom auth handler and tried the following in the Startup:

 services.AddAuthentication("Basic")
        .AddScheme<BasicAuthenticationOptions, EdcAuthenticationHandler>("Basic", null);

 services.AddAuthorization();

I also have

app.UseAuthentication();

but, again, there is no app.UseAuthorization()

I want to be able to add [Authorize] attributes (with roles as well) and be able to access the User object inside my controller methods.

Any insight would be appreciated.

1 Answer 1

2

Turns out it was simple. I needed the authorization tag like this:

[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]

And

services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
    .AddScheme<BasicAuthenticationOptions, EdcAuthenticationHandler>(JwtBearerDefaults.AuthenticationScheme, null);

There was no need for: app.UseAuthorization();

Sorry for the trouble. Just couldn't figure out that I needed the scheme name in the authorize tag.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.