languages | page_type | name | description | products | urlFragment | ||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
sample |
.NET MAUI Multi-platform App Sign-in user |
This .NET Multi-platform App UI (.NET MAUI) app signs in the user and then makes a request to Microsoft Graph for the user's profile data. The code in this sample is used by one or more articles on docs.microsoft.com. |
|
ms-identity-docs-code-csharp-maui |
This sample demonstrates a Windows desktop and Android mobile .NET MAUI Multi-platform App that sign-in users by using the Microsoft.Identity.Client
.
📃 This sample application backs one or more technical articles on docs.microsoft.com.
- An Azure Active Directory (Azure AD) tenant. You can open an Azure account for free to get an Azure AD instance.
- .NET 6.0 SDK
- .NET MAUI
- Install apps from any source enabled in Windows' developer settings
- Device Emulators are configured
First, complete the steps in Register an application with the Microsoft identity platform to register the sample app.
Use the following settings for your app registration:
App registration setting |
Value for this sample app | Notes |
---|---|---|
Name | active-directory-dotnet-xplat-maui |
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) | Required for this sample. Support for the Single tenant. |
Platform type | Mobile and desktop applications |
Required value for this sample. Enables the required and optional settings for the app type. |
Redirect URI | https://login.microsoftonline.com/common/oauth2/nativeclient |
Required value for this sample. You can change that later in your own implementation. |
ℹ️ Bold text in the table matches (or is similar to) a UI element in the Azure portal, while
code formatting
indicates a value you enter into a text box or select in the Azure portal.
-
Open the sign-in-xplat/MainPage.xaml.cs in your code editor.
private const string ClientId = "APPLICATION_(CLIENT)_ID"; private const string Tenant = "TENANT_ID";
-
Open the sign-in-xplat/Platforms/Android/AndroidManifest.xml in your code editor and replace the
APPLICATION_(CLIENT)_ID
placeholder with your Application (Client) Id.<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round"> <activity android:name="microsoft.identity.client.BrowserTabActivity" android:exported="true"> <intent-filter> ... <data android:scheme="msalAPPLICATION_(CLIENT)_ID" android:host="auth" /> </intent-filter> </activity> </application>
- Select target Android emulator and then press
F5
.
- Select Windows Machine and then press
F5
.
- Once the app is running you can sign-in with your user credentials.
This app uses the .NET MAUI Multi-platform App UI to provide a cross-platform experience in which the Microsoft Identity Client library is used to sign the user in and out of the application.
When a signed-out user clicks the sign in button, the app offers a native Azure AD sign in experience. After signing in, and if they've not previously done so, the user is asked to consent to the app's request for permission to access their data.
While signing in, a new token is acquired and passed in an Authorization header as Bearer for a subsequent call to Microsoft Graph. When a signed-out user the account is removed from the client cleaning up the user's retrieved information.
This cross-platform solution makes use of conditional compilation so that code is targeted to specific platforms when required.
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 not limited to running this or another sample app 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.