Skip to content

An example project demonstrating how to implement Basic Authentication in an ASP.NET Core application. Includes secure credential validation and protected routes.

License

Notifications You must be signed in to change notification settings

ErikFernandes/BasicAuthExample

Repository files navigation

BasicAuthExample

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.

Features

  • 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.

Technologies Used

  • ASP.NET 8.
  • Minimal dependencies to focus on authentication.

Project Structure

  1. Controllers: Contains public and protected endpoints to test authentication.
  2. Middleware: Basic Authentication implementation.

How to Use

  1. Clone the repository:
    git clone https://github.com/erikfernandes/BasicAuthExample.git
    cd BasicAuthExample
  2. Configure the project:
    Update the credentials in the BasicAuthExample/Credentials.cs file or set up your preferred data source.
  3. Run the application:
    dotnet run
  4. 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)
    

About

An example project demonstrating how to implement Basic Authentication in an ASP.NET Core application. Includes secure credential validation and protected routes.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages