Difference beetween authentication with cookies and JWT

sblb 1,231 Reputation points
2023-10-23T20:24:32.3166667+00:00

Hi, I would like to know if you can give me the difference between authentication with cookies and JWT.

Also, I would like to know if I can make an authorisation of my application Independently of the authentication method use : cookies or JWT.

Program.cs in server project : cookie method

builder.Services.ConfigureApplicationCookie(options =>
{
    options.Cookie.HttpOnly = false;
    options.Events.OnRedirectToLogin = context =>
    {
        context.Response.StatusCode = 401;
        return Task.CompletedTask;
    };
});

Program.cs in server project : cookie method

//builder.Services.AddAuthentication(opt =>
//{
//    opt.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
//    opt.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
//}).AddJwtBearer(options =>
//{
 //   options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
   // {
   //     ValidateIssuer = true,
   //     ValidateAudience = true,
   //     ValidateLifetime = true,
    //    ValidateIssuerSigningKey = true,

    //    ValidIssuer = jwtSettings["validIssuer"],
    //    ValidAudience = jwtSettings["validAudience"],
   //     IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSettings))
  //  };
//});

Thanks in advance to your reply

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,596 questions
0 comments No comments
{count} votes

6 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.