Created
November 8, 2017 20:53
-
-
Save GeorgDangl/dffdcd69090cc939575a45cf91d18553 to your computer and use it in GitHub Desktop.
Challenging multiple authentication schemes in Asp.Net Core 2.0 with a default policy on all actions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services.AddIdentity<AppUser, AppRole>(); | |
services.AddAuthentication() | |
.AddIdentityServerAuthentication(o => | |
{ | |
o.RequireHttpsMetadata = !environment.IsDevelopment(); | |
o.ApiName = "api"; | |
o.Authority = configuration["IdentityServer:Authority"]; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
services.AddMvc(options => | |
{ | |
// The default policy is to make sure that both authentication schemes - Cookie and Jwt - are challenged | |
var defaultPolicy = new AuthorizationPolicyBuilder(IdentityConstants.ApplicationScheme, "Bearer") | |
.RequireAssertion(c => true) // A requirement is mandatory | |
.Build(); | |
options.Filters.Add(new AuthorizeFilter(defaultPolicy)); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment