Prerequisites: Before you begin, ensure you have the following:
- .NET 8.0 SDK or higher (or .NET Framework 4.6.2 for legacy projects)
- Visual Studio 2022 or VS Code with the C# Dev Kit
Get Started
This quickstart demonstrates how to add Auth0 authentication to a WPF or WinForms desktop application. You’ll configure Auth0, install the SDK, and add login, logout, and user profile display using the Auth0 OIDC Client for WPF and WinForms.Create your application
If you already have a WPF or WinForms project, skip to the next step.
- .NET CLI
- Visual Studio
Create a new project and open its directory:
- WPF
- WinForms
Configure Auth0
To use Auth0 services, you need to have an application set up in the Auth0 Dashboard. The Auth0 application is where you configure how authentication works for your project.
Configure an application
Go to Auth0 Dashboard → Applications → Applications and create a new application:- Click Create Application
- Enter a name for your application
- Select Native as the application type
- Click Create
Configure Callback URLs
A callback URL is a URL in your application where Auth0 redirects users after they have authenticated. If not set, users will not be returned to your application after they log in.In your Application Settings, add the following to Allowed Callback URLs:Configure Logout URLs
A logout URL is a URL in your application where Auth0 redirects users after they have logged out. If not set, users will not be able to log out from your application and will receive an error.In your Application Settings, add the following to Allowed Logout URLs:Install the Auth0 SDK
Auth0 provides separate NuGet packages for WPF and WinForms. Install the one that matches your project type.
- NuGet Package Manager
- .NET CLI
Open the Package Manager Console (Tools → NuGet Package Manager → Package Manager Console) and run:
Instantiate the Auth0Client
To integrate Auth0 into your application, instantiate an
Auth0Client with your Auth0 Domain and Client ID. Add a private field and initialize it inside the existing constructor in your main window or form.- WPF
- WinForms
Open
MainWindow.xaml.cs and update it as follows:MainWindow.xaml.cs
Add login to your application
Use the SDK’s If there is no error, you can access
LoginAsync() method to log users in. When called, it opens a popup window with the Auth0 Universal Login page. After successful authentication, Auth0 redirects to the callback URL, and the SDK returns a LoginResult.First, add a login button to your UI:- WPF
- WinForms
Open Then add the click handler in
MainWindow.xaml and add a Button inside the <Grid>:MainWindow.xaml
MainWindow.xaml.cs:MainWindow.xaml.cs
LoginResult.User, LoginResult.IdentityToken, LoginResult.AccessToken, and LoginResult.RefreshToken on the result.Add logout to your application
Use the SDK’s
LogoutAsync() method to log users out. This opens a popup window, redirects to Auth0’s logout endpoint to clear the session, then redirects back to the logout URL you configured.First, add a logout button to your UI:- WPF
- WinForms
Open Then add the click handler in
MainWindow.xaml and add a logout Button next to the login button:MainWindow.xaml
MainWindow.xaml.cs:MainWindow.xaml.cs
Show user profile information
The To see all claims returned in the ID token:
LoginResult.User property is a ClaimsPrincipal containing the authenticated user’s profile. Query the claims to display user information in your application.CheckpointYou should now have a working Auth0-integrated WPF or WinForms application. Run your application and verify that:
- Clicking the login button opens the Auth0 Universal Login page in a popup window.
- You can log in or sign up.
- After authentication, you can access user information from
LoginResult.User. - Clicking the logout button clears the session and redirects to your logout URL.
Advanced Usage
Handle login errors
Handle login errors
Check If the user closes the login popup without authenticating,
LoginResult.IsError before accessing tokens or user properties. The Error and ErrorDescription properties contain details when authentication fails.LoginAsync() returns a result with BrowserResultType.UserCancel. This is expected behavior — do not treat it as an error.Refresh tokens
Refresh tokens
To get a new access token without requiring the user to log in again, use
RefreshTokenAsync() with the refresh token from the initial LoginResult.Refresh tokens require the
offline_access scope and must be enabled in your Auth0 Application Settings under Refresh Token Rotation.Additional Resources
SDK Repository
Source code, release notes, and issue tracker for the Auth0 OIDC Client for .NET
User Profiles
Learn about user profile claims and the /userinfo endpoint
Community Forum
Get help from the Auth0 community
Common Issues
Login popup opens but authentication never completes
Login popup opens but authentication never completes
Problem: The WebView2 popup window opens and shows the login page, but after entering credentials nothing happens.Solution: The Microsoft Edge WebView2 Runtime is not installed on the machine. Install it from the Microsoft WebView2 download page. WebView2 ships with Windows 11 and recent Windows 10 builds, but must be separately installed on older systems.
Callback URL mismatch error
Callback URL mismatch error
Problem: After logging in, Auth0 returns a
callback URL mismatch error.Solution: The redirect URI used by the SDK does not match any value in your Allowed Callback URLs in the Auth0 Dashboard. Add https://{yourDomain}/mobile to Allowed Callback URLs in your Application Settings. The SDK uses this URL by default.Logout URL mismatch error
Logout URL mismatch error
Problem: After logging out, Auth0 returns an error about an unrecognized logout URL.Solution: Add
https://{yourDomain}/mobile to Allowed Logout URLs in your Application Settings.LoginResult.IsError is true after login
LoginResult.IsError is true after login
Problem: Common causes:
LoginResult.IsError is true but there is no clear indication of the cause.Solution: Check LoginResult.Error and LoginResult.ErrorDescription for details:- The application type in the Auth0 Dashboard is not set to Native
- OIDC Conformant is not enabled under Advanced Settings → OAuth
- The JSON Web Token Signature Algorithm is not set to RS256
RefreshToken is null after login
RefreshToken is null after login
Problem: Also ensure Refresh Token Rotation is enabled in your Application Settings in the Auth0 Dashboard.
LoginResult.RefreshToken is null.Solution: The offline_access scope is required to receive a refresh token. Add it to the Scope option: