This project demonstrates how to implement Basic Authentication in an ASP.NET Core application. It is designed to serve as a simple and clear reference for developers who want to understand and implement this type of authentication in their APIs.
- Configuration of Basic Authentication with in-memory credential validation.
- User and password validation with appropriate error responses.
- Protection of API endpoints using authentication filters.
- Practical examples of protected routes.
- ASP.NET 8.
- Minimal dependencies to focus on authentication.
- Controllers: Contains public and protected endpoints to test authentication.
- Middleware: Basic Authentication implementation.
- Clone the repository:
git clone https://github.com/erikfernandes/BasicAuthExample.git cd BasicAuthExample
- Configure the project:
Update the credentials in theBasicAuthExample/Credentials.cs
file or set up your preferred data source. - Run the application:
dotnet run
- Test the endpoint using tools like Postman, Insomnia, or cURL. Use the HTTP
Authorization
header with credentials encoded in Base64:Authorization: Basic base64(username:password)