{"id":20940887,"url":"https://github.com/timhanewich/timhanewich.microsoftgraphhelper","last_synced_at":"2026-04-27T09:01:53.519Z","repository":{"id":117078191,"uuid":"355264103","full_name":"TimHanewich/TimHanewich.MicrosoftGraphHelper","owner":"TimHanewich","description":".NET Library designed to assist with the Microsoft Graph authentication and token refresh process and help with transacting with several graph services.","archived":false,"fork":false,"pushed_at":"2025-03-02T03:35:25.000Z","size":43,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-27T19:20:36.646Z","etag":null,"topics":["graph","microsoft","microsoft-graph","microsoft-graph-api","outlook","outlook-365"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/TimHanewich.MicrosoftGraphHelper/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TimHanewich.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-06T16:49:59.000Z","updated_at":"2025-03-02T03:37:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"50407a0a-7a7d-47d6-9fdc-4ca6e0777de6","html_url":"https://github.com/TimHanewich/TimHanewich.MicrosoftGraphHelper","commit_stats":null,"previous_names":["timhanewich/microsoftgraphhelper"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/TimHanewich/TimHanewich.MicrosoftGraphHelper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimHanewich%2FTimHanewich.MicrosoftGraphHelper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimHanewich%2FTimHanewich.MicrosoftGraphHelper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimHanewich%2FTimHanewich.MicrosoftGraphHelper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimHanewich%2FTimHanewich.MicrosoftGraphHelper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TimHanewich","download_url":"https://codeload.github.com/TimHanewich/TimHanewich.MicrosoftGraphHelper/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimHanewich%2FTimHanewich.MicrosoftGraphHelper/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32329466,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T23:26:28.701Z","status":"online","status_checked_at":"2026-04-27T02:00:06.769Z","response_time":128,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graph","microsoft","microsoft-graph","microsoft-graph-api","outlook","outlook-365"],"created_at":"2024-11-18T23:12:17.822Z","updated_at":"2026-04-27T09:01:53.504Z","avatar_url":"https://github.com/TimHanewich.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Microsoft Graph Helper\nThis 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`. \n\nThis library was built around the Microsoft documentation specified [here](https://learn.microsoft.com/en-us/graph/auth-v2-user).\n\nTo install the package from NuGet in your .NET project, run the following:\n```\ndotnet add package TimHanewich.MicrosoftGraphHelper\n```\n\n## Example: Authenticating with Microsoft Graph\nThe following example demonstrates using this library to authenticate with the Microsoft Graph API. \n\n*Note: The `Tenant` property, per [Microsoft documentation](https://learn.microsoft.com/en-us/graph/auth-v2-user), can be \"common\" for both Microsoft accounts and work/school accounts, \"organizations\" for work/school accounts only, \"consumers\" for Microsoft accounts only, of a tenant identifier (GUID).*\n\n```\nMicrosoftGraphHelper mgh = new MicrosoftGraphHelper();\nmgh.Tenant = \"consumers\";\nmgh.ClientId = Guid.Parse(\"d9571adf-0c99-4285-bd6c-85d1ad9df015\"); //ID of the app registration in Azure Entra ID\nmgh.RedirectUrl = \"https://www.google.com/\"; //registered redirect URL of the app registration in Azure Entra ID\nmgh.Scope.Add(\"User.Read\"); //add any scopes you want\nmgh.Scope.Add(\"Calendars.ReadWrite\");\nmgh.Scope.Add(\"Mail.Read\");\n\n\n//authorization happens via the web browser. Redirect the user to visit the url and provide consent.\n//they will redirected to the redirect URL (must be a registered redirect URL in the application in Azure AD) with a \"code\" parameter.\nstring url = mgh.AssembleAuthorizationUrl();\nConsole.WriteLine(\"Please go to the following URL and sign in. After you sign in, give me the \"code\" parameter out of the URL it redirects you to\");\nConsole.WriteLine(url);\nConsole.Write(\"Give me the code: \");\nstring code = Console.ReadLine();\nmgh.GetAccessTokenAsync(code).Wait();\n```\n\n## Example: Resuming Access After a Period of Inactivity\nNormally the bearer token you will be given will expire within 60 minutes. This means your access will also stop. However, if the `offline_access` scope was added to the original authorization flow (it is by default in the `MicrosoftGraphHelper` class), you can refresh your token by using the refresh token that was originally provided in the authorization flow. \n\nFor example:\n\n```\n// The token payload was saved to JSON previously. Here, we are retrieving it and adding it back\nMicrosoftGraphTokenPayload tokens = JsonConvert.DeserializeObject\u003cMicrosoftGraphTokenPayload\u003e(System.IO.File.ReadAllText(@\"C:\\Users\\timh\\Downloads\\tah\\TimHanewich.MicrosoftGraphHelper\\payload.json\"));\nMicrosoftGraphHelper mgh = new MicrosoftGraphHelper();\nmgh.LastReceivedTokenPayload = tokens;\n\n//Refresh if the retrieved token is expired\nif (mgh.AccessTokenHasExpired())\n{\n    Console.Write(\"Tokens are expired! Refreshing... \");\n    await mgh.RefreshAccessTokenAsync(); \n    Console.WriteLine(\"Refreshed!\");  \n}\nelse\n{\n    Console.WriteLine(\"Tokens are still active! No need to refresh.\");\n}\n```\n\n## Example: Create Outlook Calendar Event (Appointment)\nThe following demonstrates how you can schedule a new event in your user's default outlook calendar. It requires the `Calendars.ReadWrite` scope.\n\n```\n//Create Outlook Event\nOutlookEvent ev = new OutlookEvent();\nev.Subject = \"Let's do something\";\nev.Body = \"Go shopping maybe?\";\nev.StartUTC = new DateTime(2025, 03, 02, 12, 0, 0);\nev.EndUTC = ev.StartUTC.AddMinutes(15);\n\n//Schedule\nConsole.Write(\"Scheduling... \");\nawait mgh.CreateOutlookEventAsync(ev);\nConsole.WriteLine(\"done!\");\n```\n\n## Example: Send an Email via Outlook\nThe following requires the `Mail.Send` scope.\n\n```\n//Construct email\nOutlookEmailMessage email = new OutlookEmailMessage();\nemail.ToRecipients.Add(\"timhanewich@gmail.com\");\nemail.Subject = \"My favorite songs\";\nemail.Content = \"1. Chris Brown - Yeah 3X\\n2. Chris Brown - Forever\\n3. Chris Brown - Turn Up the Music\";\nemail.ContentType = OutlookEmailMessageContentType.Text;\n\n//Send email\nConsole.Write(\"Sending email... \");\nawait mgh.SendOutlookEmailMessageAsync(email);\nConsole.WriteLine(\"Sent!\");\n```\n\n## Example: Sharepoint List Manipulation\n```\n//Get the sites that are available\nSharepointSite[] sites = mgh.SearchSharepointSitesAsync(\"\").Result;\nConsole.WriteLine(JArray.Parse(JsonConvert.SerializeObject(sites)).ToString());\n\n//Get the lists in that site\nSharepointList[] lists = mgh.ListSharepointListsAsync(Guid.Parse(\"2e069086-c6f2-4735-a728-eb33b8347842\")).Result;\nConsole.WriteLine(JArray.Parse(JsonConvert.SerializeObject(lists)).ToString());\n\n//Get the content of a list\nSharepointListItem[] items = mgh.GetAllItemsFromSharepointListAsync(Guid.Parse(\"2e069086-c6f2-4735-a728-eb33b8347842\"), Guid.Parse(\"771b32f1-859c-4570-8bf2-7c86d140dc5c\")).Result;\nConsole.WriteLine(JArray.Parse(JsonConvert.SerializeObject(items)).ToString());\n\n//Creating a new item (record) in a list\nJObject jo = new JObject();\njo.Add(\"Title\", \"Harry the Hippo\");\nmgh.CreateItemAsync(Guid.Parse(\"2e069086-c6f2-4735-a728-eb33b8347842\"), Guid.Parse(\"771b32f1-859c-4570-8bf2-7c86d140dc5c\"), jo).Wait();\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimhanewich%2Ftimhanewich.microsoftgraphhelper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimhanewich%2Ftimhanewich.microsoftgraphhelper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimhanewich%2Ftimhanewich.microsoftgraphhelper/lists"}