All Projects → Azure-Samples → active-directory-dotnet-desktop-msgraph-v2

Azure-Samples / active-directory-dotnet-desktop-msgraph-v2

Licence: MIT license
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)

Programming Languages

C#
18002 projects
powershell
5483 projects

Projects that are alternatives of or similar to active-directory-dotnet-desktop-msgraph-v2

active-directory-dotnet-deviceprofile
This sample demonstrates how to leverage ADAL .NET to authenticate user calls to a web API (in this case, the directory Graph) from apps that do not have the capability of offering an interactive authentication experience.
Stars: ✭ 18 (-82.52%)
Mutual labels:  desktop-app, ms-graph
active-directory-dotnet-admin-restricted-scopes-v2
An ASP.NET MVC application that shows how to use the Azure AD v2.0 endpoint to collect consent for permissions that require administrative consent.
Stars: ✭ 46 (-55.34%)
Mutual labels:  ms-graph, aadv2
twitter-bot-bootstrap
Template for creating a twitter bot using python (twython) and heroku
Stars: ✭ 26 (-74.76%)
Mutual labels:  quickstart
ms-graph-cli
elegant cli to authenticate microsoft graph
Stars: ✭ 28 (-72.82%)
Mutual labels:  ms-graph
vue-flexible-link
Tiny Vue component for Electron to open links in a browser. Ideal for cross environment apps (Web & Native)
Stars: ✭ 22 (-78.64%)
Mutual labels:  desktop-app
auth0-xamarin-oidc-samples
Auth0 OIDC Client with Xamarin applications
Stars: ✭ 26 (-74.76%)
Mutual labels:  quickstart
showcase
Showcasing what can be done with Bastion
Stars: ✭ 19 (-81.55%)
Mutual labels:  quickstart
flutter desktop markdown reader
Experimental MacOS Markdown reader made with Flutter
Stars: ✭ 55 (-46.6%)
Mutual labels:  desktop-app
SmartsApp
💬📱 An End to End Encrypted Cross Platform messenger app.
Stars: ✭ 69 (-33.01%)
Mutual labels:  desktop-app
unicodemoticon
Trayicon with Unicode Emoticons using Python3 Qt5
Stars: ✭ 21 (-79.61%)
Mutual labels:  desktop-app
vault-quickstart
Some shell scripts to get vault up and running as quickly as possible
Stars: ✭ 11 (-89.32%)
Mutual labels:  quickstart
smartsilo
Hardware-integrated system composed by a desktop app and a Node.js server able to control an Arduino and manipulate the temperature of grains within storage silos
Stars: ✭ 33 (-67.96%)
Mutual labels:  desktop-app
quickstart-calls-directcall-ios
iOS sample for Direct Call of Sendbird Calls, guiding you to build a real-time voice and video calls quickly and easily.
Stars: ✭ 13 (-87.38%)
Mutual labels:  quickstart
joplin-note-tabs
Allows to open several notes at once in tabs and pin them.
Stars: ✭ 150 (+45.63%)
Mutual labels:  desktop-app
violin
🎵 Minimalistic music player for desktop devices.
Stars: ✭ 40 (-61.17%)
Mutual labels:  desktop-app
joplin-plugin-hotfolder
A plugin to Monitor a locale folder and import the files as a new note.
Stars: ✭ 24 (-76.7%)
Mutual labels:  desktop-app
Pixeval
Wow. Yet another Pixiv client!
Stars: ✭ 1,639 (+1491.26%)
Mutual labels:  desktop-app
orchestrate-quick-start
PegaSys Orchestrate Quick start
Stars: ✭ 19 (-81.55%)
Mutual labels:  quickstart
graderjs
💦 Turn your full-stack NodeJS application into a downloadable cross-platform binary. Also works for SPAs, or regular web-sites.
Stars: ✭ 147 (+42.72%)
Mutual labels:  desktop-app
carina-demo
Carina demo project.
Stars: ✭ 40 (-61.17%)
Mutual labels:  desktop-app
page_type languages products description
sample
csharp
azure
azure-active-directory
dotnet
ms-graph
This sample demonstrates how to use the MSAL.NET to get an access token and call the Microsoft Graph.

Build Badge

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

WPF application signing in users with Microsoft and calling the Microsoft Graph

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).

Topology

Steps to Run

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:

  1. Clone the code.
  git clone https://github.com/Azure-Samples/active-directory-dotnet-desktop-msgraph-v2.git
  1. Run the application from Visual Studio (Debug | Start without Debugging)

[Optional] Use your own application coordinates

If you want to use your own application coordinates, please follow these instructions:

Choose the Azure AD tenant where you want to create your applications

  1. Sign in to the Azure portal using either a work or school account or a personal Microsoft account.
  2. If your account gives you access to more than one tenant, select your account in the top right corner, and set your portal session to the desired Azure AD tenant (using Switch Directory).
  3. In the left-hand navigation pane, select the Azure Active Directory service, and then select App registrations.

Register the client app (WpfApp)

  1. Navigate to the Microsoft identity platform for developers App registrations page.
  2. Select New registration.
    • In the Name section, enter a meaningful application name that will be displayed to users of the app, for example WpfApp.
    • In the Supported account types section, select Accounts in any organizational directory and personal Microsoft accounts (e.g. Skype, Xbox, Outlook.com).
    • Select Register to create the application.
  3. On the app Overview page, find the Application (client) ID value and record it for later. You'll need it to configure the Visual Studio configuration file for this project.
  4. In the list of pages for the app, select Authentication.
  5. In the Redirect URIs list, under Suggested Redirect URIs for public clients (mobile, desktop) be sure to add https://login.microsoftonline.com/common/oauth2/nativeclient.
  6. Select Save.
  7. Configure Permissions for your application. To that extent in the list of pages click on API permissions
    • click the Add a permission button and then,
    • Ensure that the Microsoft APIs tab is selected
    • In the Commonly used Microsoft APIs section, click on Microsoft Graph
    • In the Delegated permissions section, ensure that the right permissions are checked: User.Read. Use the search box if necessary.

Configure the code to use your application's coordinates

  1. Open the active-directory-wpf-msgraph-v2\App.xaml.cs file
  2. Find the app key ClientId and replace the existing value with the application ID (clientId) of the WpfApp application copied from the Azure portal.
  3. If connecting to a national cloud, open the 'active-directory-wpf-msgraph-v2\MainWindow.xaml.cs' file and update string graphAPIEndpoint to the appropriate endpoint. See a list of national cloud Graph enpoints here.
  4. Run the application from Visual Studio (Debug | Start without Debugging)

Troubleshooting

System.Security.Cryptography.CryptographicException: 'Key not valid for use in specified state

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

Consider taking a moment to share your experience with us.

Community Help and Support

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.

Contributing

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.

More information

For more information see MSAL.NET's conceptual documentation:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].