blob: 18127bc1af9f0ed49fabf2e302ced6ea63a67c24 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;
namespace DevHive.Web.Configurations.Extensions
{
public static class ConfigureJwt
{
public static void JWTConfiguration(this IServiceCollection services, IConfiguration configuration)
{
// Get key from appsettings.json
var signingKey = Encoding.ASCII.GetBytes(configuration
.GetSection("Jwt")
.GetSection("signingKey")
.Value);
// Setup Jwt Authentication
services.AddAuthentication(x =>
{
x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(x =>
{
x.Events = new JwtBearerEvents
{
OnTokenValidated = context =>
{
return Task.CompletedTask;
}
};
x.RequireHttpsMetadata = false;
x.SaveToken = true;
x.TokenValidationParameters = new TokenValidationParameters
{
IssuerSigningKey = new SymmetricSecurityKey(signingKey),
ValidateIssuer = false,
ValidateAudience = false
};
});
}
}
}
|