Introduction
In this article, we learn about how to do simple authentication with the MS Graph(Microsoft Graph) API in DotNet or C# Conole App.
Description
Microsoft Graph is a Unified API. It is a Microsoft developer platform that connects multiple services and devices. Initially released in 2015, the Microsoft Graph builds on Office 365 APIs and allows developers to integrate their services with Microsoft products, including Windows, Office 365, Azure.
Microsoft Graph is a Unified API meaning that single access token created using Microsoft app registration can be used with different service and it is CORS enabled, So No More issue in Browser(CORS issue might be you have faced using Sharepoint REST Request).
Recently, I came across a scenario to build a console app in which we have to Integrate Microsoft Graph API using C#.
Prerequisite
I assume that you have an idea of Registering Microsft Graph app in Microsoft developer platform or Azure Portal (App registration is free by the way, you only need a Microsoft account).
Once the app is registered and permission is configured you need to grant admin consent, and after that the app will work, otherwise it will give an unauthorized error.
For more info, you can visit: https://docs.microsoft.com/en-us/graph/auth-v2-service
Nuget Package: See Below package file with the specific version as well.
- <packages>
- <package id="Microsoft.Graph" version="1.12.0" targetFramework="net45" />
- <package id="Microsoft.Graph.Core" version="1.12.0" targetFramework="net45" />
- <package id="Microsoft.Identity.Client" version="2.7.1" targetFramework="net45" />
- <package id="Newtonsoft.Json" version="6.0.1" targetFramework="net45" />
- </packages>
I have searched a lot for the running sample for MS Graph SDK but most of them didn't work for me. It's an older version of SDK which is not working. I have found this code from Github repo and updated with the latest SDK,
AuthenticationHelper.cs

Devesh KachhawayPosted Aug 16, 2019, 9:38 AM
I’m working on Outlook add-in, in that I have certain requirement to call graph api.I tried using your article but I’m unable to get response after authentication popup closed. After opening authentication popup and entering my credentials in popup, it get closed and but in "authResult", I don't get any response. authResult = await IdentityClientApp.AcquireTokenAsync(Scopes); Please let me know, If I’m doing anything wrong or if need to do some settings in azure.