Skip to main content

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:
Then ask your AI assistant:
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:
  • .NET SDK 8.0 or newer
  • Your favorite code editor (Visual Studio, VS Code, or Rider)
  • An Auth0 account (sign up for free)

Get Started

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
Open the project
2

Install the Auth0 SDK

3

Setup your Auth0 Application

Next up, you need to create a new Application on your Auth0 tenant and add the configuration to your project.You can choose to set up your Auth0 app automatically by running a CLI command, or do it manually via the Dashboard:
Run the following shell command on your project’s root directory to create an Auth0 Application and update your appsettings.json:
This command will:
  1. Check if you’re authenticated (and prompt for login if needed)
  2. Create an Auth0 Regular Web Application configured for http://localhost:5000
  3. Update appsettings.json with Auth0:Domain, Auth0:ClientId, and Auth0:ClientSecret
Configure Callback URLs:In the Settings tab, configure the following URLs:
  • Allowed Callback URLs: http://localhost:5000/callback
  • Allowed Logout URLs: http://localhost:5000
  • Allowed Web Origins: http://localhost:5000
Click Save Changes
Important: Make sure to setup connections and enable them for your application in the Auth0 Dashboard under the Connections tab.
4

Configure authentication

Update your Program.cs to configure Auth0 authentication:
Program.cs
5

Add Login and Logout functionality

Create an AccountController.cs in the Controllers folder:
Controllers/AccountController.cs
6

Create Profile view

Create a new file Views/Account/Profile.cshtml:
Views/Account/Profile.cshtml
Note: You’ll need to create the Views/Account directory first if it doesn’t exist.
7

Update your layout

Update your layout file to add Login/Logout buttons. In Views/Shared/_Layout.cshtml, find the <nav> element and replace it with:
Views/Shared/_Layout.cshtml
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

Your application should start and display the URL it’s listening on:
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.

Advanced Usage

You can access user profile information through the User property in your controllers or views:
Controllers/AccountController.cs
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
You can pass custom parameters to the Auth0 login page:
Controllers/AccountController.cs
If you need to call external APIs on behalf of the user, you can retrieve and store tokens:
Program.cs
Then retrieve the access token in your controller:
Controllers/ApiController.cs
Customize authentication behavior by handling events:
Program.cs

Additional Resources

GitHub Repository

Source code and issue tracker

API Reference

Detailed API documentation

Community Forum

Get help from the Auth0 community

Common Issues

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.
Also ensure:
  • No trailing slash in the domain value
  • Your application has internet access to reach Auth0
  • The domain format matches your tenant region (.auth0.com, .us.auth0.com, .eu.auth0.com)
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
Problem: Authentication not working despite correct configuration.Solution: Ensure middleware is in the correct order. UseAuthentication() must come before UseAuthorization():
Program.cs

Sample Application

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: