Skip to content

Commit 58c55b6

Browse files
Merge pull request #581 from shweaver-MSFT/shweaver/graph-updates-710
Updated Graph docs for 7.1.0 release.
2 parents f3243a5 + 3e6ef4b commit 58c55b6

File tree

14 files changed

+417
-190
lines changed

14 files changed

+417
-190
lines changed

docs/graph/authentication/ProviderManager.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ dev_langs:
1111

1212
The ProviderManager manages access to the globally configured [IProvider](./custom.md) instance and any state change events as users sign in and out.
1313

14-
> Available in the `CommunityToolkit.Authentication` package.
15-
16-
> [!IMPORTANT]
17-
> Windows Community Toolkit - Graph Controls and Helpers packages are in preview. To get started using WCT preview packages visit the [WCT Preview Packages wiki page](https://aka.ms/wct/wiki/previewpackages).
14+
Available in the `CommunityToolkit.Authentication` package.
1815

1916
## Properties
2017

2118
| Property | Type | Description |
2219
| -- | -- | -- |
20+
| ClientName | string | (*Static*) Gets the name of the toolkit client to identify self in Graph calls. |
21+
| Instance | ProviderManager | (*Static*) Get or set the instance of the globally configured IProvider. |
2322
| State | ProviderState | Gets the current authentication state of the provider. |
2423

2524
## Events

docs/graph/authentication/custom.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
---
2-
title: IProvider
2+
title: Custom authentication providers
33
author: shweaver-MSFT
44
description: IProvider interface defines the basic functions of an authentication provider in the Graph toolkit.
55
keywords: uwp, wpf, netstandard, windows, community, toolkit, graph, login, authentication, provider, providers, identity
66
dev_langs:
77
- csharp
88
---
99

10-
# Custom provider
10+
# Custom authentication providers
1111

1212
If you have existing authentication code in your application, you can create a custom provider to enable authentication and access to Microsoft Graph for the toolkit's Graph based controls and helpers. To bring your own authentication provider logic, start by extending `IProvider`.
1313

1414
## IProvider
1515

16-
`IProvider` is the base interface for creating authentication providers that work with the various controls and helpers in the toolkit. Handle authenticaiton with one of our premade `IProvider` implementations or create your own.
16+
`IProvider` is the base interface for creating authentication providers that work with the various controls and helpers in the toolkit. Handle authentication with one of our premade `IProvider` implementations or create your own.
1717

18-
> Available in the `CommunityToolkit.Authentication` package.
19-
20-
> [!IMPORTANT]
21-
> Windows Community Toolkit - Graph Controls and Helpers packages are in preview. To get started using WCT preview packages visit the [WCT Preview Packages wiki page](https://aka.ms/wct/wiki/previewpackages).
18+
Available in the `CommunityToolkit.Authentication` package.
2219

2320
```csharp
2421
using CommunityToolkit.Authentication;
@@ -47,7 +44,7 @@ ProviderManager.Instance.GlobalProvider = customProvider;
4744
| Method | Arguments | Returns | Description |
4845
| -- | -- | -- | -- |
4946
| AuthenticateRequestAsync | HttpRequestMessage | Task | Authenticate an outgoing request. |
50-
| GetTokenAsync | bool silentOnly = false, string[] scopes = null | Task<string> | Retrieve a token for the authenticated user. |
47+
| GetTokenAsync | bool silentOnly = false | Task<string> | Retrieve a token for the authenticated user. |
5148
| SignInAsync | | Task | Sign in a user. |
5249
| SignOutAsync | | Task | Sign out the current user. |
5350
| TrySilentSignInAsync | | Task<bool> | Try signing in silently, without prompts. |

docs/graph/authentication/msal.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ dev_langs:
1111

1212
The MsalProvider is an [IProvider](./custom.md) implementation built on the official Microsoft Authentication Library (MSAL). It is NetStandard 2.0 so it works in both UWP and WPF apps.
1313

14-
> Available in the `CommunityToolkit.Authentication.Msal` package.
15-
16-
> [!IMPORTANT]
17-
> Windows Community Toolkit - Graph Controls and Helpers packages are in preview. To get started using WCT preview packages visit the [WCT Preview Packages wiki page](https://aka.ms/wct/wiki/previewpackages).
14+
Available in the `CommunityToolkit.Authentication.Msal` package.
1815

1916
```csharp
2017
using CommunityToolkit.Authentication;

docs/graph/authentication/overview.md

Lines changed: 46 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ dev_langs:
99

1010
# Authentication Providers Overview
1111

12-
> [!IMPORTANT]
13-
> Windows Community Toolkit - Graph Controls and Helpers packages are in preview. To get started using WCT preview packages visit the [WCT Preview Packages wiki page](https://aka.ms/wct/wiki/previewpackages).
14-
1512
Authentication is always the first step to working with Microsoft Graph. The toolkit providers enable your application to authenticate with Microsoft Identity and access Microsoft Graph in only few lines of code. Each provider handles user authentication and acquiring access tokens to call Microsoft Graph APIs, so that you don't have to write this code yourself.
1613

1714
You can use the providers on their own, without components, to quickly implement authentication for your app and make calls to Microsoft Graph via the Microsoft Graph .NET SDK.
@@ -22,9 +19,9 @@ The toolkit includes the following providers:
2219

2320
| Providers | Description |
2421
| -- | -- |
25-
| [Msal](./msal.md) | Uses MSAL for .NET to sign in users and acquire tokens to use with Microsoft Graph in a NetStandard 2.0 application. |
26-
| [Windows](./windows.md) | Uses native WebAccountManager (WAM) APIs to sign in users and acquire tokens to use with Microsoft Graph in a UWP application. |
27-
| [Custom](./custom.md)Custom | Create a custom provider to enable authentication and access to Microsoft Graph with your application's existing authentication code. |
22+
| [Msal](./msal.md) | Uses MSAL for .NET to sign in users and acquire tokens to use with Microsoft Graph in NetStandard 2.0 applications. |
23+
| [Windows](./windows.md) | Uses native WebAccountManager (WAM) APIs to sign in users and acquire tokens to use with Microsoft Graph in UWP applications. |
24+
| [Custom](./custom.md) | Create a custom provider to enable authentication and access to Microsoft Graph with your application's existing authentication code. |
2825

2926
## Initializing the GlobalProvider
3027

@@ -69,6 +66,8 @@ public enum ProviderState
6966
}
7067
```
7168

69+
## Respond to changes in the GlobalProvider state
70+
7271
In some scenarios, you will want to show certain functionality or perform an action only after a user has successfully signed in. You can access and check the provider state as shown in the following example:
7372

7473
```csharp
@@ -79,7 +78,7 @@ if (ProviderManager.Instance.GlobalProvider?.State === ProviderState.SignedIn) {
7978
}
8079
```
8180

82-
You can also use the `ProviderUpdated` and `ProviderStateChanged` events to get notified whenever provider is set or changes state.
81+
Use the `ProviderUpdated` and `ProviderStateChanged` events to get notified whenever provider is set or changes state.
8382

8483
```csharp
8584
using CommunityToolkit.Authentication;
@@ -98,6 +97,43 @@ void OnProviderStateChanged(object sender, ProviderUpdatedEventArgs args)
9897
}
9998
```
10099

100+
### ProviderStateTrigger
101+
102+
To respond to provider state changes from XAML, try out the `ProviderStateTrigger` state trigger.
103+
104+
Available in the `CommunityToolkit.Graph.Uwp` package.
105+
106+
```xml
107+
<VisualStateManager.VisualStateGroups xmlns:uwp="using:CommunityToolkit.Graph.Uwp">
108+
<VisualStateGroup>
109+
<VisualState>
110+
<VisualState.StateTriggers>
111+
<uwp:ProviderStateTrigger State="SignedIn" />
112+
</VisualState.StateTriggers>
113+
<VisualState.Setters>
114+
<Setter Target="ContentPivot.Visibility" Value="Visible" />
115+
</VisualState.Setters>
116+
</VisualState>
117+
</VisualStateGroup>
118+
</VisualStateManager.VisualStateGroups>
119+
120+
<Pivot Name="ContentPivot" Visibility="Collapsed">
121+
<!-- The pivot will only be visible when the global provider is in a signed in state, and otherwise collapsed. -->
122+
</Pivot>
123+
```
124+
125+
### FrameworkElement.IsVisibleWhen
126+
127+
The `FrameworkElement.IsVisibleWhen` attached property makes it easy to toggle visibility for any `FrameworkElement`.
128+
129+
Available in the `CommunityToolkit.Graph.Uwp` package.
130+
131+
```xml
132+
<Pivot Name="ContentPivot" uwp:ElementExtensions.IsVisibleWhen="SignedIn">
133+
<!-- The pivot will only be visible when the global provider is in a signed in state, and otherwise collapsed. -->
134+
</Pivot>
135+
```
136+
101137
## Getting an access token
102138

103139
Each provider exposes a function called `getTokenAsync` that can retrieve the current access token or retrieve a new access token for the provided scopes. The following example shows how to get a new access token or the currently signed in user:
@@ -113,14 +149,14 @@ string token = await provider.GetTokenAsync(silentOnly: false);
113149

114150
## Call Microsoft Graph APIs
115151

116-
Once authenticated, you can now make API calls to Microsoft Graph using the Graph SDK or without.
152+
Once authenticated, you can now make API calls to Microsoft Graph using the Graph SDK or without. See the [Extensions](../helpers/extensions.md) page for an example of how to authenticate an outbound request directly.
117153

118154
### Use the Graph SDK
119155

120-
Access APIs using the Graph SDK through a preconfigured `GraphServiceClient` available through an extension method on `IProvider` called, `GetClient()`.
156+
Access APIs using the Graph SDK through a preconfigured `GraphServiceClient` available through an extension method on `IProvider` called `GetClient()` and `GetBetaClient()`.
121157
See [Microsoft Graph Extensions](../helpers/extensions.md) for more details.
122158

123-
This is the easiest way to get started because all of the Graph types are available and the `GraphServiceClient` offers a convenient way of building requests.
159+
It's possible to authenticate and make all Graph requests manually, without the Graph SDK. This can reduce package size significantly. However, using the Graph SDK is certainly the easiest way to work with Graph in .NET because the `GraphServiceClient` offers a convenient way of building requests and includes all of the object types ready to use.
124160

125161
Available in the `CommunityToolkit.Graph` package.
126162

@@ -133,50 +169,3 @@ GraphServiceClient graphClient = provider.GetClient();
133169

134170
var me = await graphClient.Me.Request().GetAsync();
135171
```
136-
137-
### Handle Graph requests manually
138-
139-
Access APIs by managing requests to Microsoft Graph yourself. This is helpful for projects with existing systems for managing web requests, or for keeping package sizes minimal by excluding the Graph SDK.
140-
141-
To make Graph API calls manually, use the `IProvider.AuthenticateRequestAsync(HttpRequestMessage)` method to authenticate an outgoing request.
142-
143-
```csharp
144-
using CommunityToolkit.Authentication;
145-
using Newtonsoft.Json;
146-
using Newtonsoft.Json.Linq;
147-
148-
private async Task<IList<TodoTask>> GetDefaultTaskListAsync()
149-
{
150-
return await GetResponseAsync<List<TodoTask>>("https://graph.microsoft.com/v1.0/me/todo/lists/tasks/tasks");
151-
}
152-
153-
private async Task<T> GetResponseAsync<T>(string requestUri)
154-
{
155-
// Build the request
156-
HttpRequestMessage getRequest = new HttpRequestMessage(HttpMethod.Get, requestUri);
157-
158-
// Authenticate the request
159-
await ProviderManager.Instance.GlobalProvider.AuthenticateRequestAsync(getRequest);
160-
161-
var httpClient = new HttpClient();
162-
using (httpClient)
163-
{
164-
// Send the request
165-
var response = await httpClient.SendAsync(getRequest);
166-
167-
if (response.IsSuccessStatusCode)
168-
{
169-
// Handle the request response
170-
var jsonResponse = await response.Content.ReadAsStringAsync();
171-
var jObject = JObject.Parse(jsonResponse);
172-
if (jObject.ContainsKey("value"))
173-
{
174-
var result = JsonConvert.DeserializeObject<T>(jObject["value"].ToString());
175-
return result;
176-
}
177-
}
178-
}
179-
180-
return default;
181-
}
182-
```

docs/graph/authentication/windows.md

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ dev_langs:
1212
The WindowsProvider is an authentication provider for accessing locally configured accounts on Windows.
1313
It extends [IProvider](./custom.md) and uses the native Windows AccountManager (WAM) APIs and AccountsSettingsPane for sign in.
1414

15-
> Available in the `CommunityToolkit.Authentication.Uwp` package.
16-
17-
> [!IMPORTANT]
18-
> Windows Community Toolkit - Graph Controls and Helpers packages are in preview. To get started using WCT preview packages visit the [WCT Preview Packages wiki page](https://aka.ms/wct/wiki/previewpackages).
15+
Available in the `CommunityToolkit.Authentication.Uwp` package.
1916

2017
## Prerequisite Windows Store Association in Visual Studio
2118

@@ -30,27 +27,25 @@ To get valid tokens and complete sign in, the app will need to be associated wit
3027
> [!NOTE]
3128
> You must have a Windows Developer account to use the WindowsProvider in your UWP app. You can [register a Microsoft developer account](https://developer.microsoft.com/store/register) if you don't already have one.
3229
33-
<!-- Uncomment this when AAD account support becomes available.
3430
## Prerequisite Configure Client Id in Partner Center
3531

3632
If your product integrates with Azure AD and calls APIs that request either application permissions or delegated permissions that require administrator consent, you will also need to enter your Azure AD Client ID in Partner Center:
3733

38-
https://partner.microsoft.com/en-us/dashboard/products/&lt;YOUR-APP-ID&gt;/administrator-consent
34+
`https://partner.microsoft.com/dashboard/products/&lt;YOUR-APP-ID&gt;/administrator-consent`
3935

4036
This lets administrators who acquire the app for their organization grant consent for your product to act on behalf of all users in the tenant.
4137

4238
> [!NOTE]
43-
> You only need to specify the client id if you need admin consent for delegated permissions from your AAD app registration. Simple authentication for public accounts does not require a client id or any additional configuration.
39+
> You only need to specify the client id if you need admin consent for delegated permissions from your AAD app registration, or need to support more advanced authentication scenarios like SSO. Simple authentication for consumer MSA accounts does not require a client id or any additional configuration in Azure for basic access.
4440
4541
> [!IMPORTANT]
46-
> Be sure to Register Client Id in Azure first following the guidance here: <https://docs.microsoft.com/azure/active-directory/develop/quickstart-register-app>
42+
> Make sure to Register Client Id in Azure first following the guidance here: [Quickstart: Register an application with the Microsoft identity platform](/azure/active-directory/develop/quickstart-register-app)
4743
>
48-
> After finishing the initial registration page, you will also need to add an additional redirect URI. Click on "Add a Redirect URI" and add the value retrieved from running `WindowsProvider.RedirectUri`.
44+
> After finishing the initial registration page, you will also need to add an additional redirect URI. Click on "Add a Redirect URI" and add the value retrieved from running `WindowsProvider.RedirectUri` at runtime.
4945
>
50-
> You'll also want to set the toggle to true for "Allow public client flows".
46+
> You'll also want to set the toggle to **true** for "Allow public client flows".
5147
>
5248
> Then click "Save".
53-
-->
5449
5550
## Syntax
5651

@@ -64,9 +59,8 @@ using CommunityToolkit.Authentication;
6459
ProviderManager.Instance.GlobalProvider = new WindowsProvider(new string[] { "User.Read", "Tasks.ReadWrite" });
6560
```
6661

67-
The WindowsProvider can also be configured to disabled auto-signin or show custom content in the `AccountsSettingsPane`.
68-
Additional configuration for account types will be available via the `WebAccountProviderConfig` object in the future.
69-
Currently, only consumer MSA accounts are supported.
62+
The WindowsProvider can also be configured to disable auto-login or show custom content in the `AccountsSettingsPane`.
63+
Configuration for specifying supported account types (such as AAD) is available via the `WebAccountProviderConfig` object.
7064

7165
```CSharp
7266
using CommunityToolkit.Authentication;
@@ -82,9 +76,11 @@ void OnSettingsCommandInvoked(IUICommand command)
8276
System.Diagnostics.Debug.WriteLine("AccountsSettingsPane command invoked: " + command.Id);
8377
}
8478

85-
// Configure which types accounts should be available to choose from. The default is MSA, but AAD will come in the future.
86-
// ClientId is only required for approving admin level consent in AAD tenants.
87-
var webAccountProviderConfig = new WebAccountProviderConfig(WebAccountProviderType.MSA, "YOUR_CLIENT_ID_HERE");
79+
// Configure which types of accounts should be available to choose from. The default is MSA, but AAD is also supported.
80+
var webAccountProviderConfig = new WebAccountProviderConfig(WebAccountProviderType.Msa);
81+
82+
// ClientId is only required for approving admin level consent in AAD tenants or for supporting advanced authentication scenarios like SSO.
83+
//var webAccountProviderConfig = new WebAccountProviderConfig(WebAccountProviderType.Aad, "YOUR_CLIENT_ID_HERE");
8884
8985
// Configure details to present in the AccountsSettingsPane, such as custom header text and links.
9086
var accountsSettingsPaneConfig = new AccountsSettingsPaneConfig(

0 commit comments

Comments
 (0)