{"id":13542751,"url":"https://github.com/CommunityToolkit/Graph-Controls","last_synced_at":"2025-04-02T11:30:52.478Z","repository":{"id":37151402,"uuid":"208158113","full_name":"CommunityToolkit/Graph-Controls","owner":"CommunityToolkit","description":"Set of Helpers and Controls for Windows development using the Microsoft Graph.","archived":false,"fork":false,"pushed_at":"2023-04-18T00:40:50.000Z","size":791,"stargazers_count":153,"open_issues_count":31,"forks_count":39,"subscribers_count":9,"default_branch":"main","last_synced_at":"2024-08-01T11:08:32.156Z","etag":null,"topics":["authentication","graph-request","graph-sdk","graphserviceclient","msal","netstandard","uwp"],"latest_commit_sha":null,"homepage":"https://docs.microsoft.com/en-us/windows/communitytoolkit/graph/overview","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CommunityToolkit.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2019-09-12T22:42:46.000Z","updated_at":"2024-07-26T12:19:31.000Z","dependencies_parsed_at":"2024-01-16T17:02:05.751Z","dependency_job_id":"5d6d1c00-5e52-4b3a-90e7-0d5cf902377e","html_url":"https://github.com/CommunityToolkit/Graph-Controls","commit_stats":null,"previous_names":["windows-toolkit/graph-controls"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CommunityToolkit%2FGraph-Controls","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CommunityToolkit%2FGraph-Controls/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CommunityToolkit%2FGraph-Controls/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CommunityToolkit%2FGraph-Controls/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CommunityToolkit","download_url":"https://codeload.github.com/CommunityToolkit/Graph-Controls/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246806479,"owners_count":20837106,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["authentication","graph-request","graph-sdk","graphserviceclient","msal","netstandard","uwp"],"created_at":"2024-08-01T11:00:16.932Z","updated_at":"2025-04-02T11:30:52.048Z","avatar_url":"https://github.com/CommunityToolkit.png","language":"C#","readme":"# Windows Community Toolkit - Graph Helpers and Controls\n\nWelcome! This is a sub-repo for the [Windows Community Toolkit](https://aka.ms/wct) focused on [Microsoft Graph](https://developer.microsoft.com/en-us/graph/) providing a set of Authentication and Graph helpers for Windows applications.\n\nNote: This new library replaces the `Microsoft.Toolkit.Uwp.UI.Controls.Graph` package; however, it is not backwards compatible nor does it provide all the same features at this time.\n\nIf you need similar controls for the Web, please use the [Microsoft Graph Toolkit](https://aka.ms/mgt).\n\n## \u003ca name=\"supported\"\u003e\u003c/a\u003e Supported SDKs\n\n| Package | Min Supported |\n|--|--|\n| `CommunityToolkit.Authentication` | NetStandard 2.0 |\n| `CommunityToolkit.Authentication.Msal` | NetStandard 2.0, UWP, .NET 6, .NET 6 Windows 10.0.17763.0, .NET Core 3.1 |\n| `CommunityToolkit.Authentication.Uwp` | UWP Windows 10.0.17134.0 |\n| `CommunityTookit.Graph` | NetStandard 2.0 |\n| `CommunityToolkit.Graph.Uwp` | UWP Windows 10.0.17763.0 |\n\n## Samples\n\nCheck out our samples for getting started with authentication providers and making calls to Microsoft Graph:\n\n- [UwpWindowsProviderSample](./Samples/UwpWindowsProviderSample)\n- [UwpMsalProviderSample](./Samples/UwpMsalProviderSample)\n- [WpfNetCoreMsalProviderSample](./Samples/WpfNetCoreMsalProviderSample)\n- [WpfNetMsalProviderSample](./Samples/WpfNetWindowsMsalProviderSample)\n- [ManualGraphRequestSample](./Samples/ManualGraphRequestSample)\n\n### Contoso Notes Sample\n\n[Contoso Notes](https://github.com/CommunityToolkit/Sample-Graph-ContosoNotes) is a premier sample note-taking app infused with Graph powered features and controls from the Windows Community Toolkit, demonstrated in practical application scenarios.\n\n## \u003ca name=\"documentation\"\u003e\u003c/a\u003e Getting Started\n\nTo get started using Graph data in your application, you'll first need to enable authentication.\n\n### 1A. Setup authentication with MSAL\n\nLeverage the official Microsoft Authentication Library (MSAL) to enable authentication in any NetStandard application.\n\n1. Register your app in Azure AAD\n    \n    Before requesting data from [Microsoft Graph](https://graph.microsoft.com), you will need to [register your application](https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app) to get a **ClientID**.\n\n    \u003e After finishing the initial registration page, you will also need to add an additional redirect URI. Click on \"Add a Redirect URI\", then \"Add a platform\", and then on \"Mobile and desktop applications\". Check the `https://login.microsoftonline.com/common/oauth2/nativeclient` checkbox on that page. Then click \"Configure\".\n\n3. Install the `CommunityToolkit.Authentication.Msal` package.\n4. Set the GlobalProvder to a new instance of MsalProvider with clientId and pre-configured scopes:\n    \n    ```csharp\n    using CommunityToolkit.Authentication;\n\n    string clientId = \"YOUR-CLIENT-ID-HERE\";\n    string[] scopes = new string[] { \"User.Read\" };\n\n    ProviderManager.Instance.GlobalProvider = new MsalProvider(clientId, scopes);\n    ```\n\n\u003e Note: You can use the `Scopes` property to preemptively request permissions from the user of your app for data your app needs to access from Microsoft Graph.\n\n### 1B. Setup authentication with WindowsProvider\n\nTry out the WindowsProvider to enable authentication based on the native Windows Account Manager (WAM) APIs in your UWP apps, without requiring a dependency on MSAL.\n\n1. Associate your app with the Microsoft Store. The app association will act as our minimal app registration for authenticating consumer MSAs. See the [WindowsProvider docs](https://docs.microsoft.com/windows/communitytoolkit/graph/authentication/windows) for more details.\n1. Install the `CommunityToolkit.Authentication.Uwp` package.\n1. Set the GlobalProvider to a new instance of WindowsProvider with pre-configured scopes:\n\n    ```csharp\n    using CommunityToolkit.Authentication;\n\n    string[] scopes = new string[] { \"User.Read\" };\n\n    ProviderManager.Instance.GlobalProvider = new WindowsProvider(scopes);\n    ```\n\n### 2. Make a Graph request with the Graph SDK\n\nOnce you are authenticated, you can then make requests to the Graph using the GraphServiceClient instance.\n\n\u003e Install the `CommunityToolkit.Graph` package.\n\n```csharp\nusing CommunityToolkit.Authentication;\nusing CommunityToolkit.Graph.Extensions;\n\nProviderManager.Instance.ProviderStateChanged += OnProviderStateChanged;\n\nvoid OnProviderStateChanged(object sender, ProviderStateChangedEventArgs args)\n{\n    var provider = ProviderManager.Instance.GlobalProvider;\n    if (provider?.State == ProviderState.SignedIn)\n    {\n        var graphClient = provider.GetClient();\n        var me = await graphClient.Me.Request().GetAsync();\n    }\n}\n```\n\n#### Make a Graph request manually\n\nAlternatively if you do not wish to use the Graph SDK you can make requests to Microsoft Graph manually instead:\n\n```csharp\nusing CommunityToolkit.Authentication;\nusing Newtonsoft.Json;\nusing Newtonsoft.Json.Linq;\n\nprivate async Task\u003cIList\u003cTodoTask\u003e\u003e GetDefaultTaskListAsync()\n{\n    var httpClient = new HttpClient();\n    var requestUri = \"https://graph.microsoft.com/v1.0/me/todo/lists/tasks/tasks\";\n\n    var getRequest = new HttpRequestMessage(HttpMethod.Get, requestUri);\n    await ProviderManager.Instance.GlobalProvider.AuthenticateRequestAsync(getRequest);\n\n    using (httpClient)\n    {\n        var response = await httpClient.SendAsync(getRequest);\n\n        if (response.IsSuccessStatusCode)\n        {\n            var jsonResponse = await response.Content.ReadAsStringAsync();\n            var jObject = JObject.Parse(jsonResponse);\n            if (jObject.ContainsKey(\"value\"))\n            {\n                var tasks = JsonConvert.DeserializeObject\u003cList\u003cTodoTask\u003e\u003e(jObject[\"value\"].ToString());\n                return tasks;\n            }\n        }\n    }\n\n    return null;\n}\n```\n\n**That's all you need to get started!**\n\nYou can use the `ProviderManager.Instance` to listen to changes in authentication status with the `ProviderStateChanged` event or get direct access to the [.NET Graph Beta API](https://github.com/microsoftgraph/msgraph-beta-sdk-dotnet) through `ProviderManager.Instance.GlobalProvider.GetBetaClient()`, just be sure to check if the `GlobalProvider` has been set first and its `State` is `SignedIn`:\n\n```csharp\nusing CommunityToolkit.Authentication;\nusing CommunityToolkit.Graph.Extensions;\n\npublic ImageSource GetMyPhoto()\n{\n    IProvider provider = ProviderManager.Instance.GlobalProvider;\n    \n    if (provider?.State == ProviderState.SignedIn)\n    {\n        // Get the beta client\n        GraphServiceClient betaGraphClient = provider.GetBetaClient();\n\n        try\n        {\n            // Make a request to the beta endpoint for the current user's photo.\n            var photoStream = await betaGraphClient.Me.Photo.Content.Request().GetAsync();\n\n            using var ras = photoStream.AsRandomAccessStream();\n            var bitmap = new BitmapImage();\n            await bitmap.SetSourceAsync(ras);\n\n            return bitmap;\n        }\n        catch\n        {\n        }\n    }\n\n    return null;\n}\n```\n\n## Feedback and Requests\nPlease use [GitHub Issues](https://github.com/CommunityToolkit/Graph-Controls/issues) for bug reports and feature requests.\n\n## Principles\nThis project has adopted the code of conduct defined by the [Contributor Covenant](http://contributor-covenant.org/)\nto clarify expected behavior in our community.\nFor more information see the [.NET Foundation Code of Conduct](http://dotnetfoundation.org/code-of-conduct).\n\n## .NET Foundation\nThis project is supported by the [.NET Foundation](http://dotnetfoundation.org).\n","funding_links":[],"categories":["Libraries"],"sub_categories":["What We Track"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCommunityToolkit%2FGraph-Controls","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FCommunityToolkit%2FGraph-Controls","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCommunityToolkit%2FGraph-Controls/lists"}