Sample showing how a Windows desktop .NET (WPF) application can get an access token using MSAL.NET and call the Microsoft Graph API or other APIs protected by the Microsoft identity platform (Azure Active Directory v2)
page_type: sample languages:
This sample is for MSAL 4.x, if you are interested in the same code for MSAL 2.x, look at the releases tab or the previousVersions/Msal2x branch
Getting Started | Library | Docs | Support |
---|
This simple sample demonstrates how to use the Microsoft Authentication Library (MSAL) for .NET to get an access token and call the Microsoft Graph (using OAuth 2.0 against the Microsoft identity platform endpoint).
You can get full explanation about this sample, and build it from scratch by going to Windows desktop .NET guided walkthrough.
This sample is pre-configured. If you just want to quickly run it just:
git clone https://github.com/Azure-Samples/active-directory-dotnet-desktop-msgraph-v2.git
If you want to use your own application coordinates, please follow these instructions:
WpfApp
.active-directory-wpf-msgraph-v2\App.xaml.cs
fileClientId
and replace the existing value with the application ID (clientId) of the WpfApp
application copied from the Azure portal.graphAPIEndpoint
to the appropriate endpoint. See a list of national cloud Graph enpoints here.
What happens You execute the app on my machine, zip the bin\release folder and share it with a colleague and this does no longer work with an exception (see #56 for details).
How to remediate
Remove the tokencache file (which ends in .msalcache.bin3
) from the bin\debug
and bin\release
folder before moving your app to the new system. The token cache in this sample uses DPAPI, which is only for you
We use Stack Overflow with the community to provide support. We highly recommend you ask your questions on Stack Overflow first and browse existing issues to see if someone has asked your question before. Make sure that your questions or comments are tagged with [msal.dotnet].
If you find a bug in the sample please raise the issue on GitHub Issues.
If you find a bug in msal.Net, please raise the issue on MSAL.NET GitHub Issues.
To provide a recommendation, visit our User Voice page.
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.
For more information see MSAL.NET's conceptual documentation: