WPF / Winforms
Download this sample project configured with your Auth0 API Keys.
This tutorial and seed project have been tested with the following:
- Microsoft Visual Studio 2015
- .NET Framework 4.6.1
This tutorial explains how to integrate Auth0 with a WPF or Winforms application.
Auth0.WinformsOrWPF helps you authenticate users with any Auth0 supported identity provider.
Install Auth0.WinformsOrWPF NuGet Package
Use the NuGet Package Manager (Tools -> Library Package Manager -> Package Manager Console) to install the Auth0.WinformsOrWPF package, running the command:
Set up the Auth0 Callback URL
Go to the Application Settings section in the Auth0 dashboard and make sure that Allowed Callback URLs contains the following value:
There are three options to do the integration:
- Using Auth0 Lock inside a Web View (this is the simplest with only a few lines of code required).
- Creating your own UI (more work, but higher control the UI and overall experience).
- Using specific user name and password.
Option 1: Auth0 Lock
To start with, we'd recommend using Lock. Here is a snippet of code to copy & paste on your project.
Since we are using
await (.NET 4.5 or greater), your method needs to be
using Auth0.Windows; var auth0 = new Auth0Client( "YOUR_AUTH0_DOMAIN", "YOUR_CLIENT_ID");
var user = await auth0.LoginAsync(this); /* Use this object to do wonderful things, e.g.: - get user email => user.Profile["email"].ToString() - get Windows Azure AD groups => user.Profile["groups"] - etc. */
Please note that an
UnauthorizedAccessException will be thrown when the user cancels the authentication dialog, so you will need to wrap the call to
LoginAsync in a try-catch block.
For WPF apps you should use
auth0.LoginAsync(new WindowWrapper(new WindowInteropHelper(this).Handle)) instead of
Option 2: Custom User Interface
If you know which identity provider you want to use, you can add a
connection parameter and the user will be sent straight to the specified
var user = await auth0.LoginAsync(this, "auth0waadtests.onmicrosoft.com") // connection name here
connection names can be found on Auth0 dashboard. E.g.:
Option 3: Specific Username and Password
var user = await auth0.LoginAsync( "my-db-connection", // connection name here "username", "password");
Accessing User Information
Auth0User has the following properties:
Profile: returns a
Newtonsoft.Json.Linq.JObjectobject (from Json.NET component) containing all available user attributes (e.g.:
IdToken: is a Json Web Token (JWT) containing all of the user attributes and it is signed with your client secret. This is useful to call your APIs and flow the user identity.
access_tokenthat can be used to access Auth0's API. You would use this for example to link user accounts.