languages | page_type | name | description | products | urlFragment | |||||
---|---|---|---|---|---|---|---|---|---|---|
|
sample |
WinUI 3 Packaged Desktop App that makes a request to the Graph API after signing in the user |
This .NET 6 (C#) WinUI 3 Packaged Desktop App signs in the user and then makes a request to Microsoft Graph for the user's profile data. |
|
ms-identity-docs-code-app-csharp-winui |
.NET (C#) | WinUI 3 Packaged Desktop App | user sign-in, protected web API access (Microsoft Graph) | Microsoft identity platform
This .NET WinUI 3 Packaged Desktop App authenticates a user and then makes a request to the Graph API as the authenticated user. The response to the request is presented to the user.
- Azure Active Directory (Azure AD) tenant and the permissions or role required for managing app registrations in the tenant.
- Visual Studio 2022, configured with WinUI 3 workload and components
First, complete the steps in Register an application with the Microsoft identity platform to register the application.
Use these settings in your app registration.
App registration setting |
Value for this sample app | Notes |
---|---|---|
Name | active-directory-dotnet-winui3 |
Suggested value for this sample. You can change the app name at any time. |
Supported account types | Accounts in this organizational directory only (Single tenant) | Suggested value for this sample. |
Platform type | Mobile and desktop applications | Required value for this sample |
Redirect URIs | https://login.microsoftonline.com/common/oauth2/nativeclient |
Required value for this sample |
ℹ️ Bold text in the tables above matches (or is similar to) a UI element in the Azure portal, while
code formatting
indicates a value you enter into a text box in the Azure portal.
Next, open the MsalExamples.csproj project in Visual Studio.
Finally, set the following values in MainWindow.xaml.cs.
// 'Tenant ID' of your Azure AD instance - this value is a GUID
TenantId = "",
// 'Application (client) ID' of app registration in Azure portal - this value is a GUID
ClientId = ""
Run the application by pressing F5 in Visual Studio.
The application will open allowing you to click the Sign In (if needed) & Call Graph button to use the authentication flow.
This .NET 6 WinUI 3 Packaged Desktop App presents a button that initiates an authentication flow using the Microsoft Authentication Library (MSAL). The user completes this flow in their default web browser. Upon successful authentication, an HTTP GET request to the Microsoft Graph /me endpoint is issued with the user's access token in the HTTP header. The response from the GET request is then displayed to the user. The MSAL client first looks to its token cache, refreshing if necessary, before acquiring a new access token.
If you can't get the sample working, you've checked Stack Overflow, and you've already searched the issues in this sample's repository, open an issue report the problem.
- Search the GitHub issues in the repository - your problem might already have been reported or have an answer.
- Nothing similar? Open an issue that clearly explains the problem you're having running the sample app.
⚠️ WARNING: Any issue in this repository not limited to running one of its sample apps will be closed without being addressed.
For all other requests, see Support and help options for developers | Microsoft identity platform.
If you'd like to contribute to this sample, see CONTRIBUTING.MD.
This project has adopted the Microsoft Open Source Code of Conduct. For more information, see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.