This is a template for MAUI(Multi-platform App UI) app that connects to Microsoft Graph. Test
Follow the instructions to successfully run your MAUI app with Microsoft Graph.
Install Visual Studio 2022 with MAUI development workload if you haven't already:
Every app that uses Azure AD for authentication must be registered with Azure AD. You can register app through Azure Portal or by using Azure CLI. Please follow one of the options to register your app:
Option 1: Register an app by using Azure CLI
- Install Azure CLI if you haven't already.
- Register your app on Microsoft Azure, by creating a new Azure AD app registration:
-
On macOS/Linux/in Bash
- Open terminal and change the working directory to the root of this project
- To make the setup script executable, run
chmod +x ./setup.sh
- To register the app, run
./setup.sh
- When prompted, sign in with your Microsoft 365 developer sandbox account
-
On Windows/in PowerShell
- Open PowerShell and change the working directory to the root of this project
- To register the app, run
.\setup.ps1
- When prompted, sign in with your Microsoft 365 developer sandbox account
-
Option 2: Register an app through Azure Portal
- Go to Azure Portal and login with your testing account that has Application developer or administrator permissions.
- Select Azure Active Directory, and select App Registrations from the left side bar. Then select + New registration.
- Give any name to your app. For Supported account types, select Accounts in any organizational directory (Any Azure AD directory - Multitenant) and personal Microsoft accounts (e.g. Skype, Xbox).
- Set the Redirect URI drop down to Public client/native (mobile & desktop) and enter
https://login.microsoftonline.com/common/oauth2/nativeclient
. Then, select Register.
Navigate to Overview tab and make a note of the Application (client) ID. You'll use them in the next steps.
- Clone the Hack Together repository to your local workspace or directly download the source code.
- Update app and secret (only if in the previous step you registered your app manually)
- Open the project folder
dotnet-maui-app-microsoft-graph
and double click toMAUIwithMSGraph.sln
file to open your project with Visual Studio. - Navigate to your MAUI project, and select GraphService.cs file, replace "CLIENT_ID" with
Application (client) ID
that you copied from your Azure Active Directory app.
- Open the project folder
- Select Local Machine button to run your app on your machine.
In your MAUI app, select Load User Info and log in using an Azure AD user account.
After the login, you'll see your display name mentioned in the app: