In this quickstart, you’ll use a sample application to learn how to add authentication to a desktop application. The sample application enables users to sign in and sign out and uses the Microsoft Authentication Library (MSAL) to handle authentication.
Before you begin, use the Choose a tenant type selector at the top of this page to select tenant type. Microsoft Entra ID provides two tenant configurations, workforce and external. A workforce tenant configuration is for your employees, internal apps, and other organizational resources. An external tenant is for your customer-facing apps.
If you have access to multiple tenants, use the Settings icon
in the top menu to switch to the tenant in which you want to register the application from the Directories + subscriptions menu.
Browse to Identity > Applications > App registrations and select New registration.
Enter a Name for your application, for example msal-node-desktop. Users of your app might see this name, and you can change it later.
Select Register to create the application.
Under Manage, select Authentication.
Select Add a platform > Mobile and desktop applications.
In the Redirect URIs section, enter http://localhost.
If you have access to multiple tenants, use the Settings icon
in the top menu to switch to the tenant in which you want to register the application from the Directories + subscriptions menu.
Browse to Identity > Applications > App registrations, select New registration.
Enter a Name for your application, for example Win-App-calling-MsGraph. Users of your app might see this name, and you can change it later.
In the Supported account types section, select Accounts in any organizational directory and personal Microsoft accounts (for example, Skype, Xbox, Outlook.com).
Select Register to create the application.
Under Manage, select Authentication.
Select Add a platform > Mobile and desktop applications.
In the Redirect URIs section, select https://login.microsoftonline.com/common/oauth2/nativeclient and in Custom redirect URIs add ms-appx-web://microsoft.aad.brokerplugin/{client_id} where {client_id} is the application (client) ID of your application (the same GUID that appears in the msal{client_id}://auth checkbox).
To avoid errors caused by path length limitations in Windows, we recommend extracting the archive or cloning the repository into a directory near the root of your drive.
Enter_the_Application_Id_here - is the Application (client) ID for the application you registered.
To find the value of Application (client) ID, go to the app's Overview page in the Microsoft Entra admin center.
Enter_the_Tenant_Info_Here - is set to one of the following options:
If your application supports Accounts in this organizational directory, replace this value with the Tenant Id or Tenant name (for example, contoso.microsoft.com)
If your application supports Accounts in any organizational directory, replace this value with organizations
If your application supports Accounts in any organizational directory and personal Microsoft accounts, replace this value with common.
To find the values of Directory (tenant) ID and Supported account types, go to the app's Overview page in the Microsoft Entra admin center.
You'll need to install the dependencies of this sample once:
Console
cd ms-identity-javascript-nodejs-desktop-main
npm install
Then, run the application via command prompt or console:
Console
npm start
Select Sign in to start the sign-in process.
The first time you sign in, you're prompted to provide your consent to allow the application to sign you in and access your profile. After you're signed in successfully, you'll be redirected back to the application.
To build and run the sample application in Visual Studio, follow these steps:
Select the Debug menu > Start Debugging, or press the F5 key. Your application's MainWindow is displayed.
Select the Call Microsoft Graph API button.
Sign in using your Microsoft Entra account (work or school account) or Microsoft account (live.com, outlook.com) credentials.
If you're running the application for the first time, you'll be prompted to provide consent to allow the application to access your user profile and sign you in. After consenting to the requested permissions, the application displays that you've successfully logged in.
You should see some basic token information and user data obtained from the call to the Microsoft Graph API.
Try out the Windows desktop tutorial for a complete step-by-step guide on building applications and new features, including a full explanation of this quickstart.
To enable your application to sign in users with Microsoft Entra, Microsoft Entra External ID must be made aware of the application you create. The app registration establishes a trust relationship between the app and Microsoft Entra. When you register an application, External ID generates a unique identifier known as an Application (client) ID, a value used to identify your app when creating authentication requests.
The following steps show you how to register your app in the Microsoft Entra admin center:
If you have access to multiple tenants, use the Settings icon
in the top menu to switch to your external tenant from the Directories + subscriptions menu.
Browse to Identity >Applications > App registrations.
Select + New registration.
In the Register an application page that appears;
Enter a meaningful application Name that is displayed to users of the app, for example ciam-client-app.
Under Supported account types, select Accounts in this organizational directory only.
Select Register.
The application's Overview pane displays upon successful registration. Record the Application (client) ID to be used in your application source code.
To specify your app type to your app registration, follow these steps:
Under Manage, select Authentication.
On the Platform configurations page, select Add a platform, and then select Mobile and desktop applications option.
For the Custom redirect URIs enter http://localhost, then select Configure.
Select Configure to save your changes.
To specify your app type to your app registration, follow these steps:
Under Manage, select Authentication.
On the Platform configurations page, select Add a platform, and then select Mobile and Desktop applications option.
For the Redirect URIs enter msalEnter_the_Application_Id_Here://auth, replace Enter_the_Application_Id_Here with the Application (client) ID that you copied earlier, then select Configure.
Select Save to save the changes.
To specify your app type to your app registration, follow these steps:
Under Manage, select Authentication.
On the Platform configurations page, select Add a platform, and then select Mobile and desktop applications option.
In the input field under Custom redirect URI, manually enter https://login.microsoftonline.com/common/oauth2/nativeclient, then select Configure. If you select this URI on the select box, you may get a redirect URI error.
Grant admin consent
Once you register your application, it gets assigned the User.Read permission. However, since the tenant is an external tenant, the customer users themselves can't consent to this permission. You as the tenant administrator must consent to this permission on behalf of all the users in the tenant:
From the App registrations page, select the application that you created (such as ciam-client-app) to open its Overview page.
Under Manage, select API permissions.
Select Grant admin consent for <your tenant name>, then select Yes.
Select Refresh, then verify that Granted for <your tenant name> appears under Status for the permission.
Create a user flow
Follow these steps to create a user flow a customer can use to sign in or sign up for an application.
If you have access to multiple tenants, use the Settings icon
in the top menu to switch to your external tenant from the Directories + subscriptions menu.
Browse to Identity > External Identities > User flows.
Select + New user flow.
On the Create page:
Enter a Name for the user flow, such as SignInSignUpSample.
In the Identity providers list, select Email Accounts. This identity provider allows users to sign-in or sign-up using their email address.
Note
Additional identity providers will be listed here only after you set up federation with them. For example, if you set up federation with Google, Facebook, Apple or an OIDC identity provider, you'll be able to select those additional identity providers here.
Under Email accounts, you can select one of the two options. For this tutorial, select Email with password.
Email with password: Allows new users to sign up and sign in using an email address as the sign-in name and a password as their first factor credential.
Email one-time-passcode: Allows new users to sign up and sign in using an email address as the sign-in name and email one-time passcode as their first factor credential. Email one-time passcode must be enabled at the tenant level (All Identity Providers > Email One-time-passcode) for this option to be available at the user flow level.
Under User attributes, choose the attributes you want to collect from the user upon sign-up. By selecting Show more, you can choose attributes and claims for Country/Region, Display Name, and Postal Code. Select OK. (Users are only prompted for attributes when they sign up for the first time.)
Select Create. The new user flow appears in the User flows list. If necessary, refresh the page.
Associate the desktop application with the user flow
For the customer users to see the sign-up or sign-in experience when they use your app, you need to associate your app with a user flow. Although many applications can be associated with your user flow, a single application can only be associated with one user flow.
On the sidebar menu, select Identity.
Select External Identities, then User flows.
In the User flows page, select the User flow name you created earlier, for example, SignInSignUpSample.
Under Use, select Applications.
Select Add application.
Select the application from the list such as ciam-client-app or use the search box to find the application, and then select it.
Choose Select.
Once you associate your app with a user flow, you can test your user flow by simulating a user’s sign-up or sign-in experience with your application from within the Microsoft Entra admin center. To do so, use the steps in Test your sign-up and sign-in user flow.
If you choose to download the .zip file, extract the sample app file to a folder where the total length of the path is 260 or fewer characters.
Install project dependencies
Open a console window, and change to the directory that contains the Electron sample app:
PowerShell
cd 1-Authentication\3-sign-in-electron\App
Run the following commands to install app dependencies:
PowerShell
npm install && npm update
To get the .NET MAUI desktop application sample code, download the .zip file or clone the sample .NET MAUI desktop application from GitHub by running the following command:
Enter_the_Application_Id_Here and replace it with the Application (client) ID of the app you registered earlier.
Enter_the_Tenant_Subdomain_Here and replace it with the Directory (tenant) subdomain. For example, if your tenant primary domain is contoso.onmicrosoft.com, use contoso. If you don't have your tenant name, learn how to read your tenant details.
In Visual Studio, open ms-identity-ciam-dotnet-tutorial-main/1-Authentication/2-sign-in-maui/appsettings.json file.
Find the placeholder:
Enter_the_Tenant_Subdomain_Here and replace it with the Directory (tenant) subdomain. For example, if your tenant primary domain is contoso.onmicrosoft.com, use contoso. If you don't have your tenant name, learn how to read your tenant details.
Enter_the_Application_Id_Here and replace it with the Application (client) ID of the app you registered earlier.
Open the project in your IDE (like Visual Studio or Visual Studio Code) to configure the code.
In your code editor, open the appsettings.json file in the ms-identity-ciam-dotnet-tutorial > 1-Authentication > 5-sign-in-dotnet-wpf folder.
Replace Enter_the_Application_Id_Here with the Application (client) ID of the app you registered earlier.
Replace Enter_the_Tenant_Subdomain_Here with the Directory (tenant) subdomain. For example, if your primary domain is contoso.onmicrosoft.com, replace Enter_the_Tenant_Subdomain_Here with contoso. If you don't have your primary domain, learn how to read tenant details.
You can now test the sample Electron desktop app. After you run the app, the desktop app window appears automatically:
In your terminal, run the following command:
PowerShell
npm start
On the desktop window that appears, select the Sign In or Sign up button. A browser window opens, and you're prompted to sign in.
On the browser sign-in page, type your Email address, select Next, type your Password, then select Sign in. If you don't have an account, select No account? Create one link, which starts the sign-up flow.
If you choose the sign-up option, after filling in your email, one-time passcode, new password and more account details, you complete the whole sign-up flow. You see a page similar to the following screenshot. You see a similar page if you choose the sign-in option. The page displays token ID claims.
.NET MAUI apps are designed to run on multiple operating systems and devices. You'll need to select which target you want to test and debug your app with.
Set the Debug Target in the Visual Studio toolbar to the device you want to debug and test with. The following steps demonstrate setting the Debug Target to Windows:
Select Debug Target drop-down.
Select Framework
Select net7.0-windows...
Run the app by pressing F5 or select the play button at the top of Visual Studio.
You can now test the sample .NET MAUI desktop application. After you run the application, the desktop application window appears automatically:
On the desktop window that appears, select the Sign In button. A browser window opens, and you're prompted to sign in.
During the sign in process, you're prompted to grant various permissions (to allow the application to access your data). Upon successful sign in and consent, the application screen displays the main page.
Open a console window, and change to the directory that contains the WPF desktop sample app:
Console
cd 1-Authentication\5-sign-in-dotnet-wpf
In your terminal, run the app by running the following command:
Console
dotnet run
After you launch the sample, you should see a window with a Sign-In button. Select the Sign-In button.
On the sign-in page, enter your account email address. If you don't have an account, select No account? Create one, which starts the sign-up flow. Follow through this flow to create a new account and sign in.
Once you sign in, you'll see a screen displaying successful sign-in and basic information about your user account stored in the retrieved token. The basic information is displayed in the Token Info section of the sign-in screen
Discover how Microsoft Entra External ID can provide secure, seamless sign-in experiences for your consumers and business customers. Explore tenant creation, app registration, flow customization, and account security.