Last active
May 17, 2021 12:47
-
-
Save Platonenkov/7b954f787c7bc5ce0aa30bfda437cb35 to your computer and use it in GitHub Desktop.
Authentication
This file contains 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
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddAuthentication(options => | |
{ | |
options.DefaultScheme = | |
CookieAuthenticationDefaults.AuthenticationScheme; | |
options.DefaultChallengeScheme = | |
OpenIdConnectDefaults.AuthenticationScheme; | |
}) | |
.AddCookie() | |
.AddOpenIdConnect(options => | |
{ | |
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; | |
options.Authority = "https://localhost:5001/"; | |
options.ClientId = "client_id"; | |
options.ClientSecret = "secret"; | |
options.ResponseType = OpenIdConnectResponseType.Code; | |
options.SaveTokens = true; | |
options.Scope.Add("openid"); | |
options.Scope.Add("profile"); | |
options.Scope.Add("api1"); | |
options.CallbackPath = "/signin-oidc"; | |
}); | |
This file contains 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
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme) | |
.AddJwtBearer(IdentityServerAuthenticationDefaults.AuthenticationScheme, config => | |
{ | |
config.Authority = "https://localhost:44310"; | |
config.Audience = "api1"; | |
//config.TokenValidationParameters = new TokenValidationParameters | |
//{ | |
// ClockSkew = TimeSpan.FromSeconds(5), | |
//}; | |
config.SaveToken = true; | |
config.RequireHttpsMetadata = false; | |
}); |
This file contains 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.AddCors(options => | |
{ | |
options.AddPolicy("CorsPolicy", | |
builder => | |
builder.AllowAnyOrigin() | |
.AllowAnyMethod() | |
.AllowAnyHeader() | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment