Skip to content

A middleware package that implements zero trust principles by verifying identity, device, and contextual information for every request. It could enforce multi-factor authentication (MFA), restrict access based on IP geolocation, and validate access tokens for API requests.

Notifications You must be signed in to change notification settings

menfra/auth-blaze

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Auth-Blaze

Auth-Blaze is a middleware package for C# .NET applications that enforces zero trust principles by verifying identity, device, and contextual information for every request. Auth-Blaze provides robust security through multi-factor authentication (MFA), IP geolocation restrictions, and token validation for API requests, ensuring that only trusted users and devices gain access.

Key Features

  • Zero Trust Verification: Authenticates identity, device, and request context to enforce zero trust policies.
  • Multi-Factor Authentication (MFA): Supports MFA to strengthen user authentication.
  • IP Geolocation-Based Restrictions: Limits access based on the user’s geographic location.
  • Access Token Validation: Validates access tokens for every API request to confirm authorization.
  • Customizable Policies: Easily configure access policies and thresholds for MFA, IP checks, and token validation.

Getting Started

Installation

Install Auth-Blaze via NuGet Package Manager Console:

Install-Package Auth-Blaze

Or, add it to your .csproj file:

<PackageReference Include="Auth-Blaze" Version="1.0.0" />

Setup and Configuration

To begin, initialize Auth-Blaze in your application’s startup file (e.g., Startup.cs) and configure the middleware with your desired zero trust policies.

// Startup.cs
using AuthBlaze;

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddAuthBlaze(options =>
        {
            options.EnableMFA = true;                     // Enable Multi-Factor Authentication (MFA)
            options.RestrictByGeolocation = true;         // Enable IP geolocation-based access restrictions
            options.TokenValidation = true;               // Validate access tokens for API requests
            options.AllowedGeolocations = new List<string> { "US", "DE", "CA" }; // Allowed IP geolocations
        });
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        app.UseAuthBlaze(); // Enable Auth-Blaze middleware in the request pipeline
    }
}

Usage

Auth-Blaze automatically validates requests based on identity, device, and context. When applied as middleware, it intercepts each request to ensure compliance with zero trust policies before the request reaches application endpoints.

Example 1: Enforcing Multi-Factor Authentication (MFA)

Auth-Blaze triggers MFA checks during login. If MFA is enabled, users are required to complete an additional verification step, such as entering a code from an authenticator app.

// Startup.cs
using AuthBlaze;

public class LoginService
{
    private readonly IAuthBlaze _authBlaze;

    public LoginService(IAuthBlaze authBlaze)
    {
        _authBlaze = authBlaze;
    }

    public async Task<bool> LoginAsync(string username, string password)
    {
        bool isAuthenticated = await _authBlaze.AuthenticateAsync(username, password);

        if (isAuthenticated)
        {
            bool mfaResult = await _authBlaze.EnforceMFAAsync(username);
            return mfaResult;
        }
        return false;
    }
}

Example 2: Restricting Access Based on Geolocation

Auth-Blaze can block access if the user’s IP geolocation does not match the allowed locations configured in the setup.

using AuthBlaze;

public class RequestService
{
    private readonly IAuthBlaze _authBlaze;

    public RequestService(IAuthBlaze authBlaze)
    {
        _authBlaze = authBlaze;
    }

    public void HandleRequest(HttpContext context)
    {
        if (!_authBlaze.IsGeolocationAllowed(context))
        {
            // Reject request or return a "403 Forbidden" response
            context.Response.StatusCode = 403;
            context.Response.WriteAsync("Access denied based on geolocation.");
        }
    }
}

Example Scenarios

  1. Multi-Factor Authentication: Strengthens authentication by requiring MFA for sensitive operations.
  2. IP Geolocation Blocking: Restricts access from specific countries or regions.
  3. Access Token Validation: Ensures that only authorized requests with valid tokens are processed.
  4. Contextual Device Verification: Confirms that requests originate from trusted devices, helping to prevent session hijacking.

Contributing

We welcome contributions! Please open an issue or submit a pull request if you have suggestions or improvements.

License

This project is licensed under the MIT License - see the LICENSE file for details.

#Contact For questions or feedback, please contact [[email protected]].

About

A middleware package that implements zero trust principles by verifying identity, device, and contextual information for every request. It could enforce multi-factor authentication (MFA), restrict access based on IP geolocation, and validate access tokens for API requests.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages