Skip to main content

Documentation Index

Fetch the complete documentation index at: https://auth0.com/llms.txt

Use this file to discover all available pages before exploring further.

Add login to your UWP application

This guide demonstrates how to integrate Auth0 with a Universal Windows Platform (UWP) application using the Auth0.OidcClient.UWP SDK. By the end, your app will support login, logout, and displaying user profile information. This guide uses Auth0.OidcClient.UWP version 1.x.

Prerequisites

You’ll need the following before you start:
  • Visual Studio 2019 (16.11+) or Visual Studio 2022 with the “Universal Windows Platform Development” workload installed
  • Windows 10 SDK 10.0.16299 or later (installed with the UWP workload)
  • An Auth0 account (sign up for free)

Get Started

1

Configure your Auth0 application

You need to set up an Auth0 application in your Auth0 Dashboard so your UWP app can connect.
  1. Navigate to the Auth0 Dashboard and log in
  2. Go to Applications > Applications in the left sidebar
  3. Select Create Application
  4. Enter a name for your application (for example, “My UWP App”)
  5. Select Native as the application type
  6. Select Create
  7. Go to the Settings tab on the Application Details page
  8. Note your Domain and Client ID at the top of the page—you’ll need these in your code
Note the Domain and Client ID values — you need these later
Next, configure your callback URL:
  1. On the Settings tab, scroll down to Application URIs
  2. In the Allowed Callback URLs field, enter: https://{yourDomain}/mobile
    • Example: https://mycompany.auth0.com/mobile
  3. In the Allowed Logout URLs field, enter the same URL: https://{yourDomain}/mobile
  4. Select Save Changes
The callback URL pattern https://{yourDomain}/mobile is Auth0’s standard for native applications. Your UWP app will automatically handle the redirect - no custom configuration needed.
2

Create your UWP project

If you already have a UWP project, skip to Step 3.
  1. Open Visual Studio
  2. Select File > New > Project
  3. Search for “UWP” and select Blank App (Universal Windows)
  4. Name your project (for example, “Auth0Sample”)
  5. Select Next
  6. For “Minimum version,” select Windows 10 (version 1909) or later
  7. For “Target version,” select the latest available (currently Windows 11)
  8. Select Create
Visual Studio creates your UWP project with a basic MainPage.xaml and MainPage.xaml.cs.
3

Install the Auth0 SDK

Add the Auth0.OidcClient.UWP NuGet package to your project.Using Package Manager UI (Recommended):
  1. Right-click your project in Solution Explorer
  2. Select Manage NuGet Packages
  3. Go to the Browse tab
  4. Search for “Auth0.OidcClient.UWP”
  5. Select the latest version and click Install
  6. Accept any dependency prompts
Or using Package Manager Console:
Install-Package Auth0.OidcClient.UWP
Or using dotnet CLI:
dotnet add package Auth0.OidcClient.UWP
Verify the installation completed without errors. If you see error messages, check your internet connection and try again.
4

Add login and logout to your main page

Now you’ll add login and logout buttons to your app. Update your MainPage.xaml and MainPage.xaml.cs.First, update MainPage.xaml:
<?xml version="1.0" encoding="utf-8"?>
<Page
    x:Class="Auth0Sample.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    <StackPanel Padding="20" VerticalAlignment="Center" HorizontalAlignment="Center">
        <TextBlock Text="Auth0 UWP Sample" FontSize="28" Margin="0,0,0,20" />
        
        <Button x:Name="LoginButton" Click="LoginButton_Click" Content="Login" Padding="10" />
        <Button x:Name="LogoutButton" Click="LogoutButton_Click" Content="Logout" Padding="10" Margin="0,10,0,0" />
        
        <TextBlock x:Name="UserInfoText" Margin="0,20,0,0" FontSize="14" TextWrapping="Wrap" />
    </StackPanel>
</Page>
Now update MainPage.xaml.cs:
using Auth0.OidcClient;
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace Auth0Sample
{
    public sealed partial class MainPage : Page
    {
        private Auth0Client _auth0Client;

        public MainPage()
        {
            InitializeComponent();
            InitializeAuth0();
        }

        private void InitializeAuth0()
        {
            _auth0Client = new Auth0Client(new Auth0ClientOptions
            {
                Domain = "{yourDomain}",
                ClientId = "{yourClientId}",
                RedirectUri = "https://{yourDomain}/mobile",
                PostLogoutRedirectUri = "https://{yourDomain}/mobile"
            });
        }

        private async void LoginButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var loginResult = await _auth0Client.LoginAsync();

                if (loginResult.IsError)
                {
                    if (loginResult.Error == "UserCancel")
                    {
                        UserInfoText.Text = "Login cancelled";
                        return;
                    }

                    UserInfoText.Text = $"Login failed: {loginResult.Error}";
                    return;
                }

                var userEmail = loginResult.User.FindFirst("email")?.Value ?? "Unknown";
                var userName = loginResult.User.FindFirst("name")?.Value ?? "User";

                UserInfoText.Text = $"Welcome, {userName}!\nEmail: {userEmail}";

                LoginButton.Visibility = Visibility.Collapsed;
                LogoutButton.Visibility = Visibility.Visible;
            }
            catch (Exception ex)
            {
                UserInfoText.Text = $"Error: {ex.Message}";
            }
        }

        private async void LogoutButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                await _auth0Client.LogoutAsync();

                UserInfoText.Text = "You have been logged out";
                LoginButton.Visibility = Visibility.Visible;
                LogoutButton.Visibility = Visibility.Collapsed;
            }
            catch (Exception ex)
            {
                UserInfoText.Text = $"Logout error: {ex.Message}";
            }
        }
    }
}
Replace the placeholders in the code:
  • {yourDomain} - Your Auth0 domain (e.g., mycompany.auth0.com)
  • {yourClientId} - Your Auth0 application Client ID
  • Auth0Sample - Your actual project name (match your UWP project name)
5

Run your app

Press F5 or select Debug > Start Debugging to launch your app.Expected behavior:
  1. Your UWP app launches and shows a “Login” button
  2. You tap Login → A browser window opens showing the Auth0 login page
  3. Enter your Auth0 credentials (or create a test account)
  4. After login, the browser closes automatically
  5. Your app shows your name and email
  6. The button changes to “Logout”
  7. You tap Logout → The browser opens briefly, then closes
  8. The button changes back to “Login”
If the login page doesn’t appear, verify your Domain and ClientId are correct, your Allowed Callback URL in Auth0 Dashboard matches https://{yourDomain}/mobile, and your internet connection is working.
CheckpointYou now have a fully functional Auth0 login experience in your UWP application.

Troubleshooting

Problem: Network connectivity issue or invalid configuration.Solution:
  1. Check your internet connection
  2. Verify your Domain is exactly correct (e.g., mycompany.auth0.com)
  3. Verify your ClientId is exactly correct (no spaces or typos)
  4. Make sure you’re running on Windows 10 (Fall Creators Update) or later
Problem: The redirect URL in your Auth0 application doesn’t match the one in your code.Solution:
  1. Go to Auth0 Dashboard > Applications > Your App > Settings
  2. Scroll to “Application URIs”
  3. Check that “Allowed Callback URLs” contains: https://{yourDomain}/mobile
  4. Verify this matches the RedirectUri in your code exactly
  5. Click Save Changes if you made any edits
Problem: Missing using statements or incorrect namespace references.Solution:
  1. Make sure you have using Auth0.OidcClient; at the top of MainPage.xaml.cs
  2. Rebuild the solution (Build > Rebuild Solution)
Problem: Your refresh token expired or the cached credentials are invalid.Solution:
  1. Tap Logout to clear cached tokens
  2. Tap Login again and re-authenticate
  3. If the problem persists, go to Auth0 Dashboard and clear your app’s refresh tokens
Problem: The profile scope wasn’t requested, so user claims aren’t available.Solution:
  1. Update your Auth0ClientOptions to request the profile scope:
    var options = new Auth0ClientOptions
    {
        Domain = "{yourDomain}",
        ClientId = "{yourClientId}",
        Scope = "openid profile email" // Add this line
    };
    
  2. Log out and log in again to get the updated scopes

Next Steps

You now have a working Auth0 integration in your UWP application. Explore these topics to extend your implementation:

Call a Protected API

Use your access token to authenticate requests to a backend API

Refresh Tokens

Maintain user sessions across app restarts

Organizations

Support multi-tenant, B2B applications

Customize Universal Login

Match Auth0’s login page to your brand

Role-Based Access Control

Control user permissions based on roles

Additional Resources

Auth0 OIDC Client

SDK source code and documentation on GitHub

OpenID Connect

Learn how OpenID Connect works with Auth0

Access Token Best Practices

Security best practices for access tokens