It is possible to use Microsoft Graph in an old ASP Net Core 2.1 application?
My application is using OpenID Connect to authenticate users but I need to query Microsoft Graph to get the users groups. ( Previously this was done using Azure AD Graph )
Can someone point me to some old examples of code that are working with 2.1 framework. Most of the examples I found are with new framework versions.
// Microsoft.AspNetCore.Authentication.OpenIdConnect, Version=2.1.2.0
.AddOpenIdConnect(option =>
{
option.ClientId = ClientId;
option.ClientSecret = ClientSecret;
option.Authority = $"https://login.microsoftonline.com/{Tenant}";
option.Resource = "https://graph.microsoft.net";
option.SignedOutRedirectUri = SignedOutRedirectUri;
option.CorrelationCookie.Name = "cookie name";
option.NonceCookie.Name = "nonce name";
option.NonceCookie.SecurePolicy = CookieSecurePolicy.Always;
option.CorrelationCookie.SecurePolicy = CookieSecurePolicy.Always;
....
}
The latest version of the Microsoft.Graph package is .NET Standard 2.0 and will work with .NET Core 2.1.
And this Microsoft Graph Tutorial will walk you through the very basics.
There is quite a bit to cover depending on what you are using MS Graph for, but I did find a small group of samples that may be useful.
Note: I highly encourage you to update to the latest Long Term Support (LTS) version of .NET. .NET Core 2.1 has been End-of-Lifecycle (EOL) since Aug, 2021.
I sanitized a working example I had and produced a small sample application here that is able to retrieve user groups.
Here is the GitHub Repository
The graph permissions assigned to the App Registration are as follows:
Delegated permissions: