AI Prompt
AI Prompt
Using AI to integrate Auth0? Add this prompt to Cursor, Windsurf, Copilot, Claude Code or your favourite AI-powered IDE to speed up development.
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 theAuth0.AspNetCore.Authentication SDK.
1
Create a new project
Create a new ASP.NET Core MVC project for this QuickstartOpen 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 do this automatically by running a CLI command or do it manually via the Dashboard:Configure Callback URLs:In the Settings tab, configure the following URLs:
- CLI
- Dashboard
Run the following shell command on your project’s root directory to create an Auth0 Application and update your
appsettings.json:- Mac/Linux
- Windows (PowerShell)
- Allowed Callback URLs:
http://localhost:5000/callback - Allowed Logout URLs:
http://localhost:5000 - Allowed Web Origins:
http://localhost:5000
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
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
Access User Profile Information
Access User Profile Information
You can access user profile information through the The user claims contain standard OIDC information:
User property in your controllers or views:Controllers/AccountController.cs
- Name: User’s display name
- Email: User’s email address
- Picture: User’s profile picture URL
- NameIdentifier (sub): Unique user ID
Customize Login Parameters
Customize Login Parameters
You can pass custom parameters to the Auth0 login page:
Controllers/AccountController.cs
Store Tokens for API Calls
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:
Program.cs
Controllers/ApiController.cs
Handle Authentication Events
Handle Authentication Events
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
Unable to obtain configuration
Unable to obtain configuration
Problem: Also ensure:
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.- 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)
Configuration values not found
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
Middleware order issues
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
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.