From 362f1573a3e06298d3a77ee18437bbe5d473eb1d Mon Sep 17 00:00:00 2001 From: Carlos Fung Date: Wed, 13 Aug 2025 11:53:46 +0200 Subject: [PATCH 1/2] Update windows-uwp-csharp-interactive.md --- .../native/windows-uwp-csharp/interactive.md | 99 ++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) diff --git a/articles/quickstart/native/windows-uwp-csharp/interactive.md b/articles/quickstart/native/windows-uwp-csharp/interactive.md index 50f22b2190..1d3d9dba44 100644 --- a/articles/quickstart/native/windows-uwp-csharp/interactive.md +++ b/articles/quickstart/native/windows-uwp-csharp/interactive.md @@ -11,6 +11,103 @@ locale: en-US # Add Login to Your UWP application -

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

System Requirements

This tutorial and sample project have been tested with the following:

+# Configure Auth0 + +<%= include('../_includes/_getting_started', { library: 'Windows Universal' }) %> + +<%= include('../../../_includes/_callback_url') %> + +::: note +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://${account.namespace}/mobile`. +::: + +<%= include('../../../_includes/_logout_url', { returnTo: 'https://' + account.namespace + '/mobile' }) %> + +# Integrate Auth0 in your Application + +## Install Dependencies + +Use the NuGet Package Manager Console (Tools -> NuGet Package Manager -> Package Manager Console) to install the `Auth0.OidcClient.UWP` package, running the command: + +${snippet(meta.snippets.dependencies)} + +## Trigger Authentication {{{ data-action="code" data-code="MainPage.xaml.cs" }}} + +To integrate Auth0 login into your application, simply instantiate an instance of the `Auth0Client` class, configuring the Auth0 Domain and Client ID: + +${snippet(meta.snippets.setup)} + +You can then call the `LoginAsync` method to log the user in: + +${snippet(meta.snippets.use)} + +![](/media/articles/native-platforms/windows-uwp-csharp/universal-login.png) + +This will load the Auth0 login page into a web view. You can learn how to customize the login page in this document. + +## Handle Authentication Tokens + +The returned login result will indicate whether authentication was successful, and if so contain the tokens and claims of the user. + +### 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. + +```csharp +if (loginResult.IsError) +{ + Debug.WriteLine($"An error occurred during login: {loginResult.Error}") +} +``` + +### Accessing the tokens + +On successful login, the login result will contain the ID Token and Access Token in the `IdentityToken` and `AccessToken` properties respectively. + +```csharp +if (!loginResult.IsError) +{ + Debug.WriteLine($"id_token: {loginResult.IdentityToken}"); + Debug.WriteLine($"access_token: {loginResult.AccessToken}"); +} +``` + +### 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: + +```csharp +if (!loginResult.IsError) +{ + Debug.WriteLine($"name: {loginResult.User.FindFirst(c => c.Type == "name")?.Value}"); + Debug.WriteLine($"email: {loginResult.User.FindFirst(c => c.Type == "email")?.Value}"); +} +``` + +::: note +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: + +```csharp +if (!loginResult.IsError) +{ + foreach (var claim in loginResult.User.Claims) + { + Debug.WriteLine($"{claim.Type} = {claim.Value}"); + } +} +``` + +## Logout + +To log the user out call the `LogoutAsync` method. + +```csharp +await client.LogoutAsync(); +``` From 981dd924f580d263655526204c37298d1f23fc27 Mon Sep 17 00:00:00 2001 From: Carlos Fung Date: Wed, 13 Aug 2025 15:53:22 +0200 Subject: [PATCH 2/2] Update interactive.md --- .../native/windows-uwp-csharp/interactive.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/articles/quickstart/native/windows-uwp-csharp/interactive.md b/articles/quickstart/native/windows-uwp-csharp/interactive.md index 1d3d9dba44..b6c4a1216b 100644 --- a/articles/quickstart/native/windows-uwp-csharp/interactive.md +++ b/articles/quickstart/native/windows-uwp-csharp/interactive.md @@ -45,15 +45,15 @@ ${snippet(meta.snippets.use)} ![](/media/articles/native-platforms/windows-uwp-csharp/universal-login.png) -This will load the Auth0 login page into a web view. You can learn how to customize the login page in this document. +This loads the Auth0 login page into a web view. You can learn how to customize the login page at this document. ## Handle Authentication Tokens -The returned login result will indicate whether authentication was successful, and if so contain the tokens and claims of the user. +The returned login result indicates whether authentication was successful, and if so contains the tokens and claims of the user. ### 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. +You can check the `IsError` property of the result to see whether the login has failed. The `ErrorMessage` contains more information regarding the error which occurred. ```csharp if (loginResult.IsError) @@ -64,7 +64,7 @@ if (loginResult.IsError) ### Accessing the tokens -On successful login, the login result will contain the ID Token and Access Token in the `IdentityToken` and `AccessToken` properties respectively. +On successful login, the login result contains the ID Token and Access Token in the `IdentityToken` and `AccessToken` properties respectively. ```csharp if (!loginResult.IsError) @@ -76,7 +76,7 @@ if (!loginResult.IsError) ### Obtaining the User Information -On successful login, the login result will contain the user information in the `User` property, which is a ClaimsPrincipal. +On successful login, the login result contains 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: @@ -89,7 +89,7 @@ if (!loginResult.IsError) ``` ::: note -The exact claims returned will depend on the scopes that were requested. For more information see @scopes. +The exact claims returned depends 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: