Noundry.Authnz

Sessionless OAuth 2.0 authentication for multiple providers with JWT token management. Secure, scalable, and easy to integrate into any .NET application.

80%+
Code Coverage
5+
OAuth Providers
Sessionless
Architecture
JWT
Token Management

Why Choose Noundry.Authnz?

Built for modern .NET applications that need scalable, secure authentication without the complexity.

Sessionless Design

JWT-based authentication eliminates server-side sessions, enabling true horizontal scaling and stateless architecture.

Multiple Providers

Support for Google, Microsoft, GitHub, and custom OAuth providers with unified configuration and consistent user experience.

Security First

Secure JWT token management, automatic token refresh, and built-in protection against common authentication vulnerabilities.

Get Started in 5 Minutes

Install Noundry.Authnz and configure OAuth authentication for your .NET application.

1. Installation

$ dotnet add package Noundry.Authnz

2. Configure Services

builder.Services.AddNoundryOAuth(config);

3. Add Middleware

app.UseNoundryOAuth();
Program.cs
using Noundry.Authnz.Extensions;

var builder = WebApplication.CreateBuilder(args);

// Add OAuth authentication
builder.Services.AddNoundryOAuth(options =>
{
    options.AddGoogle(clientId, clientSecret);
    options.AddMicrosoft(clientId, clientSecret);
    options.AddGitHub(clientId, clientSecret);
    options.JwtSecret = builder.Configuration["JWT_SECRET"];
    options.DefaultRedirectUri = "/Dashboard";
});

var app = builder.Build();

// Configure authentication pipeline
app.UseNoundryOAuth();
app.UseAuthentication();
app.UseAuthorization();

app.Run();

Supported OAuth Providers

Pre-configured support for popular OAuth providers with consistent configuration patterns.

Google

Google OAuth 2.0 with profile and email access

Microsoft

Azure AD and Microsoft Account integration

GitHub

GitHub OAuth for developer-focused applications

Discord

Discord OAuth for gaming and community apps

LinkedIn

LinkedIn OAuth for professional networking

Custom Provider

Add any OAuth 2.0 compliant provider

Provider Configuration

// Configure multiple providers
builder.Services.AddNoundryOAuth(options =>
{
    // Google OAuth
    options.AddGoogle(googleClientId, googleClientSecret);
    
    // Microsoft/Azure AD
    options.AddMicrosoft(msClientId, msClientSecret);
    
    // GitHub
    options.AddGitHub(githubClientId, githubClientSecret);
    
    // Discord
    options.AddDiscord(discordClientId, discordClientSecret);
    
    // Custom provider
    options.AddCustomProvider("custom", config =>
    {
        config.AuthorizationEndpoint = "https://oauth.example.com/authorize";
        config.TokenEndpoint = "https://oauth.example.com/token";
        config.UserInfoEndpoint = "https://api.example.com/user";
    });
    
    // JWT Configuration
    options.JwtSecret = builder.Configuration["JWT_SECRET"];
    options.JwtExpiration = TimeSpan.FromDays(30);
    options.DefaultRedirectUri = "/Dashboard";
});

Configuration & Setup

Configure OAuth providers and JWT settings for your application.

Environment Variables (.env)

# JWT Configuration
JWT_SECRET="your-super-secret-jwt-key-here"

# Google OAuth
GOOGLE_CLIENT_ID="123456789-abcdefghijklmnop.apps.googleusercontent.com"
GOOGLE_CLIENT_SECRET="encrypted:BDb7t3QkTRp2AbCdEfGhIjKl..."

# Microsoft OAuth
MICROSOFT_CLIENT_ID="12345678-1234-1234-1234-123456789abc"
MICROSOFT_CLIENT_SECRET="encrypted:XyZ9w8v7u6t5s4r3q2p1o0n..."

# GitHub OAuth
GITHUB_CLIENT_ID="Iv1.abcdef123456789"
GITHUB_CLIENT_SECRET="encrypted:Gh1b2c3d4e5f6g7h8i9j0k1l..."

# Application Settings
DEFAULT_REDIRECT_URI="/Dashboard"
COOKIE_DOMAIN=".myapp.com"

appsettings.json

{
  "OAuth": {
    "JwtSecret": "${JWT_SECRET}",
    "DefaultRedirectUri": "${DEFAULT_REDIRECT_URI}",
    "CookieSettings": {
      "Domain": "${COOKIE_DOMAIN}",
      "HttpOnly": true,
      "Secure": true,
      "SameSite": "Lax"
    },
    "Providers": {
      "google": {
        "ClientId": "${GOOGLE_CLIENT_ID}",
        "ClientSecret": "${GOOGLE_CLIENT_SECRET}",
        "Scopes": ["openid", "profile", "email"]
      },
      "microsoft": {
        "ClientId": "${MICROSOFT_CLIENT_ID}",
        "ClientSecret": "${MICROSOFT_CLIENT_SECRET}",
        "TenantId": "common"
      },
      "github": {
        "ClientId": "${GITHUB_CLIENT_ID}",
        "ClientSecret": "${GITHUB_CLIENT_SECRET}",
        "Scopes": ["user:email"]
      }
    }
  }
}

Usage Examples

Learn how to integrate OAuth authentication into your web application.

Basic Authentication Setup

Complete Program.cs Configuration

This example shows a complete setup with Google and Microsoft authentication.

using Noundry.Authnz.Extensions;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddRazorPages();
builder.Configuration.AddDotEnvX();

builder.Services.AddNoundryOAuth(options =>
{
    options.AddGoogle(
        builder.Configuration["GOOGLE_CLIENT_ID"],
        builder.Configuration["GOOGLE_CLIENT_SECRET"]
    );
    
    options.AddMicrosoft(
        builder.Configuration["MICROSOFT_CLIENT_ID"],
        builder.Configuration["MICROSOFT_CLIENT_SECRET"]
    );
    
    options.JwtSecret = builder.Configuration["JWT_SECRET"];
});

var app = builder.Build();

app.UseNoundryOAuth();
app.UseAuthentication();
app.UseAuthorization();

app.MapRazorPages();
app.Run();

Razor Pages Integration

Login Page with OAuth Buttons

Use Noundry.Authnz TagHelpers for easy OAuth integration in Razor Pages.

Pre-built OAuth buttons
Automatic provider detection
Responsive design
@* Pages/Auth/Login.cshtml *@
@page
@model LoginModel

<div class="max-w-md mx-auto mt-16">
    <div class="bg-white rounded-lg shadow-lg p-8">
        <h2 class="text-2xl font-bold text-center mb-6">
            Sign In
        </h2>
        
        <!-- OAuth Login Buttons -->
        <div class="space-y-4">
            <noundry-oauth-login show-all="true"></noundry-oauth-login>
        </div>
        
        <!-- Or show individual providers -->
        <div class="space-y-3 mt-6">
            <noundry-oauth-login provider="google"></noundry-oauth-login>
            <noundry-oauth-login provider="microsoft"></noundry-oauth-login>
            <noundry-oauth-login provider="github"></noundry-oauth-login>
        </div>
    </div>
</div>

User Status & Profile Display

<!-- Show when user is anonymous -->
<noundry-oauth-status show-when-anonymous="true">
    <a asp-page="/Auth/Login">Sign In</a>
</noundry-oauth-status>

<!-- Show when user is authenticated -->
<noundry-oauth-status show-when-authenticated="true"
                       show-avatar="true"
                       show-name="true"
                       show-email="true"
                       user-class="flex items-center space-x-3">
    <a asp-page="/Auth/Logout" class="text-red-600">Logout</a>
</noundry-oauth-status>
Example Output:
User Avatar
John Doe
john@example.com
Logout

API Authentication & Authorization

Protecting API Endpoints

Use JWT authentication to protect API endpoints with automatic token validation.

Automatic JWT validation
User claims access
Role-based authorization
[ApiController]
[Route("api/[controller]")]
public class ProductsController : ControllerBase
{
    // Public endpoint - no authentication required
    [HttpGet]
    public IActionResult GetProducts()
    {
        return Ok(products);
    }
    
    // Protected endpoint - authentication required
    [HttpPost]
    [Authorize]
    public IActionResult CreateProduct(Product product)
    {
        // Access user information from JWT claims
        var userId = User.FindFirst("sub")?.Value;
        var email = User.FindFirst("email")?.Value;
        
        product.CreatedBy = userId;
        return Ok(CreateProduct(product));
    }
    
    // Admin only endpoint
    [HttpDelete("{id}")]
    [Authorize(Roles = "Admin")]
    public IActionResult DeleteProduct(int id)
    {
        return Ok(DeleteProduct(id));
    }
}

Role-Based Access Control

Custom Authorization Policies

Define custom authorization policies and use claims for fine-grained access control.

Policy-based authorization
Claims-based identity
Razor Page protection
// Add authorization policies
builder.Services.AddAuthorization(options =>
{
    options.AddPolicy("AdminOnly", policy =>
        policy.RequireClaim("role", "admin"));
        
    options.AddPolicy("ManagerOrAdmin", policy =>
        policy.RequireClaim("role", "manager", "admin"));
});

// Use in controllers
[Authorize(Policy = "AdminOnly")]
public IActionResult AdminDashboard()
{
    return View();
}

Razor Page Authorization

@* Pages/Admin/Index.cshtml *@
@page
@model AdminIndexModel
@attribute [Authorize(Policy = "AdminOnly")]

<h1>Admin Dashboard</h1>

<!-- Show user information -->
<noundry-oauth-status show-when-authenticated="true"
                       show-name="true"
                       show-email="true">
</noundry-oauth-status>

<!-- Role-specific content -->
<div asp-authz-policy="AdminOnly">
    <h2>Admin Controls</h2>
    <!-- Admin-only content here -->
</div>
// Pages/Admin/Index.cshtml.cs
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc.RazorPages;

[Authorize(Policy = "AdminOnly")]
public class AdminIndexModel : PageModel
{
    public string UserName { get; set; }
    public string UserEmail { get; set; }
    
    public void OnGet()
    {
        // Access user claims from JWT token
        UserName = User.FindFirst("name")?.Value;
        UserEmail = User.FindFirst("email")?.Value;
        
        // Check specific permissions
        var canManageUsers = User.HasClaim("permission", "manage:users");
    }
}

Advanced Features

Explore advanced authentication scenarios and security features.

JWT Token Management

Automatic Refresh

Tokens automatically refresh before expiration

Secure Storage

HttpOnly cookies with proper security flags

Custom Claims

Add custom claims during token generation

Multi-Tenant Support

Tenant Isolation

Per-tenant OAuth configuration

Domain-Based Routing

Automatic tenant detection from domain

Separate Providers

Different OAuth providers per tenant

Security Features

CSRF Protection

Built-in CSRF token validation

State Parameter

OAuth state parameter for security

Secure Defaults

Security-first configuration out of the box

Ready to Add Authentication?

Start using Noundry.Authnz today and add secure, scalable OAuth 2.0 authentication to your .NET applications.