WPF / Winforms

Sample Project

Download this sample project configured with your Auth0 API Keys.

System Requirements

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:

Install-Package Auth0.WinformsOrWPF

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:

https://YOUR_AUTH0_DOMAIN/mobile

Integration

There are three options to do the integration:

  1. Using Auth0 Lock inside a Web View (this is the simplest with only a few lines of code required).
  2. Creating your own UI (more work, but higher control the UI and overall experience).
  3. 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 async:

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.
*/

Handle Exceptions

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.

WPF Applications

For WPF apps you should use auth0.LoginAsync(new WindowWrapper(new WindowInteropHelper(this).Handle)) instead of auth0.LoginAsync(this)

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 connection:

var user = await auth0.LoginAsync(this, "auth0waadtests.onmicrosoft.com") // connection name here

connection names can be found on Auth0 dashboard. E.g.: facebook, linkedin, somegoogleapps.com, saml-protocol-connection, etc.

Option 3: Specific Username and Password

var user = await auth0.LoginAsync(
  "my-db-connection",   // connection name here
  "username",
  "password");

Accessing User Information

The Auth0User has the following properties:

  • Profile: returns a Newtonsoft.Json.Linq.JObject object (from Json.NET component) containing all available user attributes (e.g.: user.Profile["email"].ToString()).
  • 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.
  • Auth0AccessToken: the access_token that can be used to access Auth0's API. You would use this for example to link user accounts.
Use Auth0 for FREECreate free Account