Skip to content

Instantly share code, notes, and snippets.

@Platonenkov
Last active May 17, 2021 12:47
Show Gist options
  • Save Platonenkov/7b954f787c7bc5ce0aa30bfda437cb35 to your computer and use it in GitHub Desktop.
Save Platonenkov/7b954f787c7bc5ce0aa30bfda437cb35 to your computer and use it in GitHub Desktop.
Authentication
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";
});
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;
});
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