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 Blazor Server application using theAuth0.AspNetCore.Authentication SDK.
1
Create a new project
Create a new Blazor Server 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
Note: The order of middleware is important.
UseAuthentication() must be called before UseAuthorization().5
Add Login and Logout pages
Create Login and Logout pages to allow users to authenticate.First, create the And add the following code snippets:
Pages folder and files:- Mac/Linux
- Windows (PowerShell)
6
Create Profile page and Update Layout
Create a custom user profile page for displaying the user’s name and claims, and update the layout to add login/logout links.First, create the Profile component:Add the following code snippets, note to add the
- Mac/Linux
- Windows (PowerShell)
MainLayout code to the top section of your layout, keeping all other parts intact.7
Run your application
http://localhost:5000. Click the Login link in the navigation. 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.CheckpointYou should now have a fully functional Auth0-protected Blazor Server application running on http://localhost:5000. Users can log in, view their profile, and log out.
Advanced Usage
Customize Login Parameters
Customize Login Parameters
You can pass custom parameters to the Auth0 login page:
Pages/Login.cshtml.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:
Program.cs
Configure Organizations
Configure Organizations
Configure organization support for B2B scenarios:Or specify organization at login time:
Program.cs
Pages/Login.cshtml.cs
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
Additional Resources
GitHub Repository
Source code and issue tracker
API Reference
Detailed API documentation
Community Forum
Get help from the Auth0 community
Sample Application
A sample application can be found below that demonstrates the integration of Auth0 with ASP.NET Core MVC.:ASP.NET Core Blazor App
Includes login, logout, user profile and other examples.