| title | WPF and Winforms Tutorial | ||||||
|---|---|---|---|---|---|---|---|
| name | WPF / Winforms | ||||||
| hybrid | false | ||||||
| language |
|
||||||
| framework |
|
||||||
| image | /media/platforms/asp.png | ||||||
| tags |
|
||||||
| snippets |
|
||||||
| alias |
|
::: panel-info System Requirements This tutorial and seed project have been tested with the following:
- Microsoft Visual Studio 2015
- .NET Framework 4.5.2 :::
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.
Use the NuGet Package Manager (Tools -> Library Package Manager -> Package Manager Console) to install the Auth0.WinformsOrWPF package, running the command:
${snippet(meta.snippets.dependencies)}
Go to the Application Settings section in the Auth0 dashboard and make sure that Allowed Callback URLs contains the following value:
https://${account.namespace}/mobileThere 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.
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:
${snippet(meta.snippets.setup)}
${snippet(meta.snippets.use)}
For WPF apps you should use
auth0.LoginAsync(new WindowWrapper(new WindowInteropHelper(this).Handle))instead ofauth0.LoginAsync(this)
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 hereconnection names can be found on Auth0 dashboard. E.g.:
somegoogleapps.com,saml-protocol-connection, etc.
var user = await auth0.LoginAsync(
"my-db-connection", // connection name here
"username",
"password");The Auth0User has the following properties:
Profile: returns aNewtonsoft.Json.Linq.JObjectobject (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: theaccess_tokenthat can be used to access Auth0's API. You would use this for example to link user accounts.
Browse the samples on GitHub from here.
Congratulations!
