Windows Graph Controls
This is a sub-repo for the Windows Community Toolkit focused on Microsoft Graph providing a set of Helpers and Controls for development on Windows 10 with .NET.
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.
If you need similar controls for the Web, please use the Microsoft Graph Toolkit.
Supported SDKs
- Windows 10 18362 (🚧 TODO: Check Lower SDKs)
- Android via Uno.Graph-Controls use
Uno.Microsoft.Graph.Controls
package. - 🚧 Coming Soon 🚧
- PeoplePicker control
- XAML Islands Sample
- iOS (Waiting on MSAL#1378 merge should be 4.4.0?)
Getting Started
Before using controls that access Microsoft Graph, you will need to register your application to get a ClientID.
After finishing the initial registration page, you will also need to add an additional redirect URI. Clcik on "Add a Redirect URI" and check the
https://login.microsoftonline.com/common/oauth2/nativeclient
checkbox on that page. Then click "Save".
Android Quick Start
To include the latest preview package in your Visual Studio environment, open your Package Manager Console and type:
Install-Package Uno.Microsoft.Toolkit.Graph.Controls -IncludePrerelease
Then open your shared MainPage.xaml.cs
file and add the following initialization in your constructor:
var ClientId = "YOUR_CLIENT_ID_HERE";
_ = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
{
ProviderManager.Instance.GlobalProvider = await QuickCreate.CreateMsalProviderAsync(
ClientId,
#if __ANDROID__
$"msal{ClientId}://auth", // Need to change redirectUri on Android for protocol registration from AndroidManifest.xml, ClientId needs to be updated there as well to match above.
#endif
scopes: new string[] { "user.read", "user.readbasic.all", "people.read" });
});
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.
Then also update the data
tag in your AndroidManifest.xml file:
<data android:scheme="msalYOUR_CLIENT_ID_HERE" android:host="auth" />
You need this for the protocol redirect after the user authenticates.
That's all you need to get started!
You can add any of the controls now to your XAML pages like we've done in our sample.
You can use the ProviderManager.Instance
to listen to changes in authentication status with the ProviderUpdated
event or get direct access to the .NET Graph Beta API through ProviderManager.Instance.GlobalProvider.Graph
, just be sure to check if the GlobalProvider
has been set first and its State
is SignedIn
:
var provider = ProviderManager.Instance.GlobalProvider;
if (provider != null && provider.State == ProviderState.SignedIn)
{
// Do graph call here with provider.Graph...
}
UWP Quick Start
Visit the windows-toolkit/graph-controls repo for instructions on using the library on UWP.
Build Status
Target | Branch | Status | Recommended package version |
---|---|---|---|
Pre-release beta testing | master | - |
Feedback and Requests
Please use GitHub Issues for bug reports and feature requests.
Principles
This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community. For more information see the .NET Foundation Code of Conduct.
.NET Foundation
This project is supported by the .NET Foundation.