Advertisement
Guest User

Untitled

a guest
Jul 21st, 2021
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.88 KB | None | 0 0
  1. services.AddAuthentication(options =>
  2.             {
  3.                 options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
  4.                 options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
  5.                 options.DefaultForbidScheme = JwtBearerDefaults.AuthenticationScheme;
  6.             }).
  7.                 AddJwtBearer(options =>
  8.                 {
  9.                     options.TokenValidationParameters = new TokenValidationParameters
  10.                     {
  11.                         ValidateIssuer = true,
  12.                         ValidateAudience = true,
  13.                         ValidateLifetime = true,
  14.                         ValidateIssuerSigningKey = true,
  15.                         RequireExpirationTime = true,
  16.                         ValidAudience = JWTConfig.ValidAudience,
  17.                         ValidIssuer = JWTConfig.ValidIssuer,
  18.                         IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(JWTConfig.SecretKey)),
  19.                         ClockSkew = TimeSpan.FromSeconds(10),
  20.                         NameClaimType = JwtClaimTypes.NickName
  21.                     };
  22.                     options.Events = new JwtBearerEvents
  23.                     {
  24.                         OnMessageReceived = context =>
  25.                         {
  26.                             context.Token = context.Request.Cookies["accessToken"];
  27.  
  28.                             return Task.CompletedTask;
  29.                         },
  30.                         OnChallenge = context =>
  31.                         {
  32.                             context.Response.Headers.Append("Access-Control-Allow-Origin", Origins.SafeChatView);
  33.                             context.Response.Headers.Append("Access-Control-Allow-Credentials", "true");
  34.  
  35.                             return Task.CompletedTask;
  36.                         }
  37.                     };
  38.                 });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement