This project demonstrates how to implement JWT (JSON Web Token) Authentication in an ASP.NET Core Web API. It includes secure endpoints, token generation, and Swagger integration for testing.
- JWT Token generation via login endpoint
- Secure API endpoints using
[Authorize] - Swagger UI integration with JWT support
- Configuration via
appsettings.json
- ASP.NET Core 8
- C#
- Swagger (Swashbuckle)
- JWT Bearer Authentication
- .NET Dependency Injection
JWT-Authentication-in-.NET-Core-Web-API/
│
├── Controllers/
│ └── AuthController.cs
│ └── MyRequestController.cs
│
├── Models/
│ └── LoginInfo.cs
│
├── Program.cs
├── appsettings.json
└── README.md
- User sends credentials to
/api/Auth/Login. - If valid, a JWT token is returned.
- Token is passed in the
Authorizationheader asBearer <token>. - Secure endpoints require
[Authorize]and validate the token.
- Run the project.
- Open Swagger UI at
/swagger. - Use the Authorize button to enter your JWT token:
- Call secure endpoints like
/api//MyRequest/GetMySecureData.
Update appsettings.json with your JWT settings:Ideally read this from Azure key vault
"Jwt": {
"Key": "your_super_secret_key_here",
"Issuer": "yourIssuer",
"Audience": "yourAudience"
}