Sessionless OAuth 2.0 authentication for multiple providers with JWT token management. Secure, scalable, and easy to integrate into any .NET application.
Built for modern .NET applications that need scalable, secure authentication without the complexity.
JWT-based authentication eliminates server-side sessions, enabling true horizontal scaling and stateless architecture.
Support for Google, Microsoft, GitHub, and custom OAuth providers with unified configuration and consistent user experience.
Secure JWT token management, automatic token refresh, and built-in protection against common authentication vulnerabilities.
Install Noundry.Authnz and configure OAuth authentication for your .NET application.
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();
Pre-configured support for popular OAuth providers with consistent configuration patterns.
Google OAuth 2.0 with profile and email access
Azure AD and Microsoft Account integration
GitHub OAuth for developer-focused applications
Discord OAuth for gaming and community apps
LinkedIn OAuth for professional networking
Add any OAuth 2.0 compliant provider
// 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";
});
Configure OAuth providers and JWT settings for your application.
# 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"
{
"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"]
}
}
}
}
Learn how to integrate OAuth authentication into your web application.
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();
Use Noundry.Authnz TagHelpers for easy OAuth integration in Razor Pages.
@* 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>
<!-- 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>
Use JWT authentication to protect API endpoints with automatic token validation.
[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));
}
}
Define custom authorization policies and use claims for fine-grained access control.
// 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();
}
@* 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");
}
}
Explore advanced authentication scenarios and security features.
Tokens automatically refresh before expiration
HttpOnly cookies with proper security flags
Add custom claims during token generation
Per-tenant OAuth configuration
Automatic tenant detection from domain
Different OAuth providers per tenant
Built-in CSRF token validation
OAuth state parameter for security
Security-first configuration out of the box
Start using Noundry.Authnz today and add secure, scalable OAuth 2.0 authentication to your .NET applications.