Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- services.AddAuthentication(options =>
- {
- options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
- options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
- options.DefaultForbidScheme = JwtBearerDefaults.AuthenticationScheme;
- }).
- AddJwtBearer(options =>
- {
- options.TokenValidationParameters = new TokenValidationParameters
- {
- ValidateIssuer = true,
- ValidateAudience = true,
- ValidateLifetime = true,
- ValidateIssuerSigningKey = true,
- RequireExpirationTime = true,
- ValidAudience = JWTConfig.ValidAudience,
- ValidIssuer = JWTConfig.ValidIssuer,
- IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(JWTConfig.SecretKey)),
- ClockSkew = TimeSpan.FromSeconds(10),
- NameClaimType = JwtClaimTypes.NickName
- };
- options.Events = new JwtBearerEvents
- {
- OnMessageReceived = context =>
- {
- context.Token = context.Request.Cookies["accessToken"];
- return Task.CompletedTask;
- },
- OnChallenge = context =>
- {
- context.Response.Headers.Append("Access-Control-Allow-Origin", Origins.SafeChatView);
- context.Response.Headers.Append("Access-Control-Allow-Credentials", "true");
- return Task.CompletedTask;
- }
- };
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement