0% found this document useful (0 votes)
6 views2 pages

ASP.NET Core JWT Authentication Setup

This document outlines the setup of an ASP.NET Core application using Entity Framework Core for database access, Identity for user authentication, and JWT for secure token-based authentication. It configures services such as database context, identity options, authentication schemes, and authorization. Additionally, it sets up Swagger for API documentation and defines the middleware pipeline for handling requests and responses.

Uploaded by

Keshav Bharadwaj
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

ASP.NET Core JWT Authentication Setup

This document outlines the setup of an ASP.NET Core application using Entity Framework Core for database access, Identity for user authentication, and JWT for secure token-based authentication. It configures services such as database context, identity options, authentication schemes, and authorization. Additionally, it sets up Swagger for API documentation and defines the middleware pipeline for handling requests and responses.

Uploaded by

Keshav Bharadwaj
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

using System.

Text;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];

var builder = [Link](args);

// EF Core
[Link]<ApplicationDbContext>(options =>

[Link]([Link]("DefaultConnection")
));

// Identity
[Link]<ApplicationUser, IdentityRole>(options =>
{
[Link] = true;
[Link] = false;
[Link] = false;
[Link] = false;
[Link] = 6;
})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();

// JWT
var key = [Link]([Link]["Jwt:Key"]!);

[Link](options =>
{
[Link] = [Link];
[Link] = [Link];
})
.AddJwtBearer(options =>
{
[Link] = false;
[Link] = true;
[Link] = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = [Link]["Jwt:Issuer"],
ValidAudience = [Link]["Jwt:Audience"],
IssuerSigningKey = new SymmetricSecurityKey(key)
};
});

[Link]();

// Services
[Link]<IAuthService, AuthService>();
[Link]<BookService>();
[Link]();
[Link]();
[Link]();

var app = [Link]();

[Link]();
[Link]();

[Link]();
[Link]();
[Link]();

[Link]();

[Link]();

You might also like