TimHanewich.MicrosoftGraphHelper
1.0.0
See the version list below for details.
dotnet add package TimHanewich.MicrosoftGraphHelper --version 1.0.0
NuGet\Install-Package TimHanewich.MicrosoftGraphHelper -Version 1.0.0
<PackageReference Include="TimHanewich.MicrosoftGraphHelper" Version="1.0.0" />
<PackageVersion Include="TimHanewich.MicrosoftGraphHelper" Version="1.0.0" />
<PackageReference Include="TimHanewich.MicrosoftGraphHelper" />
paket add TimHanewich.MicrosoftGraphHelper --version 1.0.0
#r "nuget: TimHanewich.MicrosoftGraphHelper, 1.0.0"
#:package TimHanewich.MicrosoftGraphHelper@1.0.0
#addin nuget:?package=TimHanewich.MicrosoftGraphHelper&version=1.0.0
#tool nuget:?package=TimHanewich.MicrosoftGraphHelper&version=1.0.0
Microsoft Graph Helper
This is a .NET class library designed to assist with the Microsoft Graph Authentication process as well as with transacting with several graph modules. This library is available on NuGet as TimHanewich.MicrosoftGraphHelper.
To Install
dotnet add package TimHanewich.MicrosoftGraphHelper
Step 1: User Provides Consent
The core class in this library is the MicrosoftGraphHelper class. After creating a new instance of MicrosoftGraphHelper, there are several inputs you make that will be used in the authentication process.
- Tenant ID
- Client ID
- Scope
- Redirect URL
After inputting these you can then assemble the URL that users will need to navigate to in order to provide consent. Use the
AssembleAuthorizationUrlmethod to assemble this consent URL.
Step 2: Use Authorization code to gain Access
After the user provides consent, they will be redirected to the redirect URL you specified in the request (and registered app in Azure). You will find the code parameter attached the URL. This code parameter is what is used to gain an access token. And the access token is what you use to transact with the graph API service.
To convert this code variable to an access token, provide this to the GetAccessTokenAsync method. Your access token will be stored in the MicrosoftGraphTokenPayload class as the LastReceivedTokenPayload property.
Example: Authenticating with Microsoft Graph
MicrosoftGraphHelper mgh = new MicrosoftGraphHelper();
mgh.TenantId = Guid.Parse("1e85f23f-c0af-4bce-bb96-92014d3c1359");
mgh.ClientId = Guid.Parse("d9571adf-0c99-4285-bd6c-85d1ad9df015");
mgh.RedirectUrl = "https://www.google.com/";
mgh.Scope.Add("Sites.ReadWrite.All");
//authorization via the web browser. Redirect the user to visit the url and provide consent.
//they will redirected to the redirect URL (must be a registered redirect URL in the application in Azure AD) with a "code" parameter.
string url = mgh.AssembleAuthorizationUrl();
Console.WriteLine(url);
Console.Write("Give me the code: ");
string code = Console.ReadLine();
mgh.GetAccessTokenAsync(code).Wait();
Example: Sharepoint List Manipulation
//Get the sites that are available
SharepointSite[] sites = mgh.SearchSharepointSitesAsync("").Result;
Console.WriteLine(JArray.Parse(JsonConvert.SerializeObject(sites)).ToString());
//Get the lists in that site
SharepointList[] lists = mgh.ListSharepointListsAsync(Guid.Parse("2e069086-c6f2-4735-a728-eb33b8347842")).Result;
Console.WriteLine(JArray.Parse(JsonConvert.SerializeObject(lists)).ToString());
//Get the content of a list
SharepointListItem[] items = mgh.GetAllItemsFromSharepointListAsync(Guid.Parse("2e069086-c6f2-4735-a728-eb33b8347842"), Guid.Parse("771b32f1-859c-4570-8bf2-7c86d140dc5c")).Result;
Console.WriteLine(JArray.Parse(JsonConvert.SerializeObject(items)).ToString());
//Creating a new item (record) in a list
JObject jo = new JObject();
jo.Add("Title", "Harry the Hippo");
mgh.CreateItemAsync(Guid.Parse("2e069086-c6f2-4735-a728-eb33b8347842"), Guid.Parse("771b32f1-859c-4570-8bf2-7c86d140dc5c"), jo).Wait();
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Newtonsoft.Json (>= 13.0.1)
-
net5.0
- Newtonsoft.Json (>= 13.0.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on TimHanewich.MicrosoftGraphHelper:
| Package | Downloads |
|---|---|
|
Aletheia
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.