Use this file to discover all available pages before exploring further.
This Quickstart is currently in Beta. We’d love to hear your feedback!
Use AI to integrate Auth0
If you use an AI coding assistant like Claude Code, Cursor, or GitHub Copilot, you can add Auth0 authentication automatically in minutes using agent skills.Install:
Add Auth0 JWT authentication to my ASP.NET Core Web API
Your AI assistant will automatically create your Auth0 API, fetch credentials, install the Auth0 ASP.NET Core Authentication API SDK, configure JWT bearer authentication, and implement protected API endpoints. Full agent skills documentation →
Prerequisites: Before you begin, ensure you have the following installed:
This quickstart demonstrates how to add Auth0 JWT authentication to an ASP.NET Core Web API. You’ll build a secure API with protected endpoints using the Auth0 ASP.NET Core API SDK.
1
Create a new project
Create a new ASP.NET Core Web API project for this Quickstart
Next up, you need to create a new API on your Auth0 tenant and add the configuration to your project.You can choose to do this automatically by running a CLI command or do it manually via the Dashboard:
CLI
Dashboard
Run the following shell command on your project’s root directory to create an Auth0 API and update your appsettings.json file:
Identifier: https://my-api (this becomes your Audience)
Signing Algorithm: RS256
Click Create
Replace YOUR_AUTH0_DOMAIN in appsettings.json with your Domain from the Test tab (e.g., your-tenant.auth0.com)
Replace YOUR_AUTH0_API_IDENTIFIER in appsettings.json with your Identifier (e.g., https://my-api)
Your Domain should not include https:// - use only the domain name (e.g., your-tenant.auth0.com).The Audience (API Identifier) is a unique identifier for your API and can be any valid URI. It doesn’t need to be a publicly accessible URL.
4
Configure authentication
Replace the entire contents of Program.cs with the following code:
2. Create a controller:Create Controllers/MessagesController.cs:
Controllers/MessagesController.cs
using Microsoft.AspNetCore.Authorization;using Microsoft.AspNetCore.Mvc;namespace Auth0Api.Controllers;[ApiController][Route("api/[controller]")]public class MessagesController : ControllerBase{ [HttpGet] public IActionResult GetPublic() { return Ok(new { Message = "This endpoint is public" }); } [Authorize] [HttpGet("private")] public IActionResult GetPrivate() { var userId = User.FindFirst("sub")?.Value; return Ok(new { Message = "This endpoint is protected", UserId = userId }); } [Authorize(Policy = "read:messages")] [HttpGet("messages")] public IActionResult GetMessages() { return Ok(new { Messages = new[] { "Message 1", "Message 2" } }); }}
Protecting Routes with Scope-Based Authorization
Protect endpoints based on specific scopes in the access token.1. Define scopes in your Auth0 API:In the Auth0 Dashboard → APIs → Your API → Permissions, add scopes:
Problem: Token validation fails with audience mismatch error.Solution: Ensure the Audience in appsettings.json exactly matches the Identifier of your Auth0 API. The audience claim in the token must match this value.
{ "Auth0": { "Audience": "https://my-api" // Must match Auth0 API Identifier }}
401 Unauthorized - Invalid issuer
Problem: Token validation fails with issuer error.Solution: Verify your Domain is correct and does not include https://. The library automatically constructs the authority as https://{Domain}.
{ "Auth0": { "Domain": "your-tenant.auth0.com" // No https:// }}
Configuration values not found
Problem:ArgumentNullException: Value cannot be null. (Parameter 'Domain') or similar.Solution: Ensure appsettings.json contains the Auth0 section with Domain and Audience values. Check that configuration is being read correctly:
builder.Services.AddAuth0ApiAuthentication(options =>{ options.Domain = builder.Configuration["Auth0:Domain"] ?? throw new InvalidOperationException("Auth0:Domain is required"); options.JwtBearerOptions = new JwtBearerOptions { Audience = builder.Configuration["Auth0:Audience"] ?? throw new InvalidOperationException("Auth0:Audience is required") };});
HTTPS certificate errors in development
Problem: SSL/TLS certificate errors when running locally.Solution: Trust the development certificate:
Problem: Authentication not working despite correct configuration.Solution: Ensure middleware is in the correct order. UseAuthentication() must come before UseAuthorization():
app.UseAuthentication(); // Must be before UseAuthorizationapp.UseAuthorization();app.MapControllers();
Scopes not working in authorization policies
Problem: Scope-based authorization policies always fail.Solution: Ensure your access token includes the required scopes. When requesting a token, specify the scopes:
curl --request POST \ --url https://YOUR_DOMAIN/oauth/token \ --data '{"client_id":"...","client_secret":"...","audience":"...","grant_type":"client_credentials","scope":"read:messages write:messages"}'
Also verify scopes are defined in your Auth0 API settings (Dashboard → APIs → Your API → Permissions).
A complete sample application demonstrating all features is available in the SDK repository.
Playground Application
Includes public and protected endpoints, DPoP support, Swagger UI integration, and Postman collection
Clone and run:
git clone https://github.com/auth0/aspnetcore-api.gitcd aspnetcore-api/Auth0.AspNetCore.Authentication.Api.Playground# Update appsettings.json with your Auth0 configurationdotnet run