> ## Documentation Index
> Fetch the complete documentation index at: https://docs-dev-docs-event-stream-action-templates.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Add login to your UWP application

> Integrate Auth0 with your Universal Windows Platform application using the Auth0.OidcClient.UWP SDK

export const HowToSchema = () => <script type="application/ld+json">
    {'{"@context":"https://schema.org","@type":"HowTo"}'}
  </script>;

<HowToSchema />

# 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](https://auth0.com/signup))

***

## Get Started

<Steps>
  <Step title="Configure your Auth0 application" stepNumber={1}>
    You need to set up an Auth0 application in your Auth0 Dashboard so your UWP app can connect.

    1. Navigate to the [Auth0 Dashboard](https://manage.auth0.com/) 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>
      Note the Domain and Client ID values — you need these later
    </Note>

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

    <Note>
      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.
    </Note>
  </Step>

  <Step title="Create your UWP project" stepNumber={2}>
    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`.
  </Step>

  <Step title="Install the Auth0 SDK" stepNumber={3}>
    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:**

    ```powershell theme={null}
    Install-Package Auth0.OidcClient.UWP
    ```

    **Or using dotnet CLI:**

    ```bash theme={null}
    dotnet add package Auth0.OidcClient.UWP
    ```

    Verify the installation completed without errors. If you see error messages, check your internet connection and try again.
  </Step>

  <Step title="Add login and logout to your main page" stepNumber={4}>
    Now you'll add login and logout buttons to your app. Update your `MainPage.xaml` and `MainPage.xaml.cs`.

    First, update `MainPage.xaml`:

    ```xaml theme={null}
    <?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`:

    ```csharp theme={null}
    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)
  </Step>

  <Step title="Run your app" stepNumber={5}>
    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"

    <Tip>
      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.
    </Tip>
  </Step>
</Steps>

<Check>
  **Checkpoint**

  You now have a fully functional Auth0 login experience in your UWP application.
</Check>

***

## Troubleshooting

<AccordionGroup>
  <Accordion title="Login page doesn't open">
    **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
  </Accordion>

  <Accordion title="Callback URL mismatch error">
    **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
  </Accordion>

  <Accordion title="Application crashes after login">
    **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)
  </Accordion>

  <Accordion title="Invalid grant error during login">
    **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
  </Accordion>

  <Accordion title="No user information is displayed">
    **Problem:** The `profile` scope wasn't requested, so user claims aren't available.

    **Solution:**

    1. Update your Auth0ClientOptions to request the profile scope:
       ```csharp theme={null}
       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
  </Accordion>
</AccordionGroup>

***

## Next Steps

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

<CardGroup cols={2}>
  <Card title="Call a Protected API" icon="plug" href="/docs/quickstart/backend/nodejs#call-your-api">
    Use your access token to authenticate requests to a backend API
  </Card>

  <Card title="Refresh Tokens" icon="rotate" href="/docs/secure/tokens/refresh-tokens">
    Maintain user sessions across app restarts
  </Card>

  <Card title="Organizations" icon="building" href="/docs/manage-users/organizations">
    Support multi-tenant, B2B applications
  </Card>

  <Card title="Customize Universal Login" icon="paintbrush" href="/docs/authenticate/login/auth0-universal-login">
    Match Auth0's login page to your brand
  </Card>

  <Card title="Role-Based Access Control" icon="shield-halved" href="/docs/manage-users/access-control/rbac">
    Control user permissions based on roles
  </Card>
</CardGroup>

***

## Additional Resources

<CardGroup cols={3}>
  <Card title="Auth0 OIDC Client" icon="github" href="https://github.com/auth0/auth0-oidc-client-net">
    SDK source code and documentation on GitHub
  </Card>

  <Card title="OpenID Connect" icon="book" href="/docs/authenticate/protocols/openid-connect-protocol">
    Learn how OpenID Connect works with Auth0
  </Card>

  <Card title="Access Token Best Practices" icon="key" href="/docs/secure/tokens/access-tokens">
    Security best practices for access tokens
  </Card>
</CardGroup>
