Docs

WPF / Winforms

View on Github

WPF / Winforms

Group 7 Copy 8

This tutorial demonstrates how to add user login to a Windows Forms C# application using Auth0. We recommend you to Log in to follow this quickstart with examples configured for your account.

I want to explore a sample app

2 minutes

Get a sample configured with your account settings or check it out on Github.

View on Github
System requirements: Microsoft Visual Studio 2017 | .NET Framework 4.5.2

New to Auth? Learn How Auth0 works, how it integrates with Native Applications and which protocol it uses.

Support

Configure Auth0

Preferred AWS Regions

Get Your Application Keys

When you signed up for Auth0, a new application was created for you, or you could have created a new one.

You will need some details about that application to communicate with Auth0. You can get these details from the Application Settings section in the Auth0 dashboard.

You need the following information:

  • Domain
  • Client ID

If you download the sample from the top of this page these details are filled out for you.

If you have more than one application in your account, the sample comes with the values for your Default App.

App Dashboard

DNS Records

Configure Callback URLs

A callback URL is a URL in your application where Auth0 redirects the user after they have authenticated.

The callback URL for your app must be whitelisted in the Allowed Callback URLs field in your Application Settings. If this field is not set, users will be unable to log in to the application and will get an error.

If you are following along with the sample project you downloaded from the top of this page, you should set the Allowed Callback URLs to https://YOUR_DOMAIN/mobile.

Sample Domain Name Sets

Configure Logout URLs

A logout URL is a URL in your application that Auth0 can return to after the user has been logged out of the authorization server. This is specified in the returnTo query parameter.

The logout URL for your app must be whitelisted in the Allowed Logout URLs field in your Application Settings. If this field is not set, users will be unable to log out from the application and will get an error.

If you are following along with the sample project you downloaded from the top of this page, the logout URL you need to whitelist in the Allowed Logout URLs field is https://YOUR_DOMAIN/mobile.

Domain Name Patterns

Integrate Auth0 in your Application

Administrator Email Addresses

Install Dependencies

The Auth0.OidcClient.WPF or Auth0.OidcClient.WinForms NuGet packages helps you authenticate users with any Auth0 supported identity provider.

Use the NuGet Package Manager (Tools -> Library Package Manager -> Package Manager Console) to install the Auth0.OidcClient.WPF or Auth0.OidcClient.WinForms package, depending on whether you are building a WPF or Windows Forms application:

Group Email Address

Trigger Authentication

To integrate Auth0 login into your application, simply instantiate an instance of the Auth0Client class, passing your Auth0 Domain and Client ID in the constructor.

You can then call the LoginAsync method to log the user in:

This will load the Auth0 login page into a web view. You can learn how to customize the login page in this document.

SMTP Settings

Handle Authentication Tokens

The returned login result will indicate whether authentication was successful, and if so contain the tokens and claims of the user.

Custom Domain

Authentication Error

You can check the IsError property of the result to see whether the login has failed. The ErrorMessage will contain more information regarding the error which occurred.

Keep Reading

Accessing the tokens

On successful login, the login result will contain the ID Token and Access Token in the IdentityToken and AccessToken properties respectively.

Obtaining the User Information

On successful login, the login result will contain the user information in the User property, which is a ClaimsPrincipal.

To obtain information about the user, you can query the claims. You can for example obtain the user's name and email address from the name and email claims:

The exact claims returned will depend on the scopes that were requested. For more information see @scopes.

You can obtain a list of all the claims contained in the ID Token by iterating through the Claims collection:

Logout

To log the user out call the LogoutAsync method.

Use Auth0 for FREE