Skip to content

Instantly share code, notes, and snippets.

@Mirch
Created March 24, 2019 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mirch/7de85466b48a4be8b14f4ffcb71d3d51 to your computer and use it in GitHub Desktop.
Save Mirch/7de85466b48a4be8b14f4ffcb71d3d51 to your computer and use it in GitHub Desktop.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<BlueInkDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("BlueInkDb")));
services.AddSingleton<HashingService>();
services.Configure<AuthenticationSettings>(Configuration.GetSection("AuthenticationSettings"));
var signingKey = Encoding.UTF8.GetBytes(Configuration.GetSection("AuthenticationSettings")
.GetValue<string>("JwtKey"));
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(x =>
{
x.RequireHttpsMetadata = false;
x.SaveToken = true;
x.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(signingKey),
ValidateIssuer = false,
ValidateAudience = false
};
});
services.AddMvc()
.AddNewtonsoftJson();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment