Use this file to discover all available pages before exploring further.
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 authentication to my ASP.NET Core MVC app
Your AI assistant will automatically create your Auth0 application, fetch credentials, install the Auth0 ASP.NET Core Authentication SDK, configure authentication middleware, and implement login/logout flows. Full agent skills documentation →
Prerequisites: Before you begin, ensure you have the following installed:
Auth0 allows you to quickly add authentication and gain access to user profile information in your application. This guide demonstrates how to integrate Auth0 with any new or existing ASP.NET MVC application using the Auth0.AspNetCore.Authentication SDK.
1
Create a new project
Create a new ASP.NET Core MVC project for this Quickstart
Next up, you need to create a new Application 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 Application and update your appsettings.json:
Enter a name for your application (e.g., “My MVC App”)
Select Regular Web Application as the application type
Click Create
Go to the Settings tab
Replace YOUR_AUTH0_DOMAIN, YOUR_CLIENT_ID, and YOUR_CLIENT_SECRET in the appsettings.json file with the Domain, Client ID, and Client Secret values from the dashboard
Configure Callback URLs:In the Settings tab, configure the following URLs:
Important: Only replace the <nav> element. Keep all other parts of _Layout.cshtml intact, especially the @RenderBody() call which is required for rendering page content.
8
Run your application
dotnet run
Your application should start and display the URL it’s listening on:
info: Microsoft.Hosting.Lifetime[14] Now listening on: http://localhost:5000
Open your browser and navigate to http://localhost:5000. Click the Login link in the navigation bar. You’ll be redirected to Auth0’s login page. After logging in, you’ll be redirected back to your application, and you should see your name in the navigation bar.
CheckpointYou should now have a fully functional Auth0-protected MVC application running on http://localhost:5000. Users can log in, view their profile, and log out.
You can access user profile information through the User property in your controllers or views:
Controllers/AccountController.cs
[Authorize]public IActionResult Profile(){ var user = new { Name = User.Identity.Name, EmailAddress = User.FindFirst(c => c.Type == System.Security.Claims.ClaimTypes.Email)?.Value, ProfileImage = User.FindFirst(c => c.Type == "picture")?.Value, UserId = User.FindFirst(c => c.Type == System.Security.Claims.ClaimTypes.NameIdentifier)?.Value }; return View(user);}
The user claims contain standard OIDC information:
Name: User’s display name
Email: User’s email address
Picture: User’s profile picture URL
NameIdentifier (sub): Unique user ID
Customize Login Parameters
You can pass custom parameters to the Auth0 login page:
Controllers/AccountController.cs
public async Task Login(string returnUrl = "/"){ var authenticationProperties = new LoginAuthenticationPropertiesBuilder() .WithRedirectUri(returnUrl) .WithParameter("screen_hint", "signup") // Show signup page .WithParameter("ui_locales", "es") // Set language to Spanish .Build(); await HttpContext.ChallengeAsync(Auth0Constants.AuthenticationScheme, authenticationProperties);}
Store Tokens for API Calls
If you need to call external APIs on behalf of the user, you can retrieve and store tokens:
Then retrieve the access token in your controller:
Controllers/ApiController.cs
[Authorize]public async Task<IActionResult> CallApi(){ var accessToken = await HttpContext.GetTokenAsync("access_token"); // Use the access token to call your API var client = new HttpClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); var response = await client.GetAsync("https://your-api.example.com/data"); var data = await response.Content.ReadAsStringAsync(); return View(data);}
Handle Authentication Events
Customize authentication behavior by handling events:
Problem:Unable to obtain configuration from: https://your-tenant.auth0.com/.well-known/openid-configurationSolution: Verify your Domain is correct and does not include https://. The library automatically constructs the authority.
Your application has internet access to reach Auth0
The domain format matches your tenant region (.auth0.com, .us.auth0.com, .eu.auth0.com)
Configuration values not found
Problem:ArgumentNullException: Value cannot be null. (Parameter 'Domain') or similar.Solution: Ensure appsettings.json contains the Auth0 section with Domain, ClientId, and ClientSecret values. Check that configuration is being read correctly:
Program.cs
builder.Services.AddAuth0WebAppAuthentication(options =>{ options.Domain = builder.Configuration["Auth0:Domain"] ?? throw new InvalidOperationException("Auth0:Domain is required"); options.ClientId = builder.Configuration["Auth0:ClientId"] ?? throw new InvalidOperationException("Auth0:ClientId is required"); options.ClientSecret = builder.Configuration["Auth0:ClientSecret"] ?? throw new InvalidOperationException("Auth0:ClientSecret is required");});
Middleware order issues
Problem: Authentication not working despite correct configuration.Solution: Ensure middleware is in the correct order. UseAuthentication() must come before UseAuthorization():
Program.cs
app.UseRouting();app.UseAuthentication(); // Must be before UseAuthorizationapp.UseAuthorization();app.MapControllerRoute(...);
A sample application can be found alongside the sourcecode for the SDK:
ASP.NET Core MVC Playgroud App
Includes login, logout, user profile and other examples.
Clone and run:
git clone https://github.com/auth0/auth0-aspnetcore-authentication.gitcd auth0-aspnetcore-authentication/playground/Auth0.AspNetCore.Authentication.Playground# Update appsettings.json with your Auth0 configurationdotnet run