├── .editorconfig
├── .gitattributes
├── .github
├── ISSUE_TEMPLATE
│ ├── bug_report.md
│ ├── documentation.md
│ ├── feature_request.md
│ └── question.md
├── PULL_REQUEST_TEMPLATE.md
└── fabricbot.json
├── .gitignore
├── CommunityToolkit.Authentication.Msal
├── CommunityToolkit.Authentication.Msal.csproj
├── MsalProvider.cs
└── MsalProviderExtensions.cs
├── CommunityToolkit.Authentication.Uwp
├── AccountsSettingsPaneConfig.cs
├── CommunityToolkit.Authentication.Uwp.csproj
├── WebAccountCommandParameter.cs
├── WebAccountProviderConfig.cs
├── WebAccountProviderType.cs
└── WindowsProvider.cs
├── CommunityToolkit.Authentication
├── BaseProvider.cs
├── CommunityToolkit.Authentication.csproj
├── Extensions
│ └── HttpRequestMessageExtensions.cs
├── IProvider.cs
├── MockProvider.cs
├── ProviderManager.cs
├── ProviderState.cs
└── ProviderStateChangedEventArgs.cs
├── CommunityToolkit.Graph.Uwp
├── Assets
│ └── person.png
├── CommunityToolkit.Graph.Uwp.csproj
├── Controls
│ ├── GraphPresenter
│ │ ├── GraphPresenter.cs
│ │ └── QueryOption.cs
│ ├── LoginButton
│ │ ├── LoginButton.Events.cs
│ │ ├── LoginButton.Properties.cs
│ │ ├── LoginButton.cs
│ │ ├── LoginButton.xaml
│ │ └── LoginFailedEventArgs.cs
│ ├── PeoplePicker
│ │ ├── PeoplePicker.cs
│ │ └── PeoplePicker.xaml
│ └── PersonView
│ │ ├── PersonAvatarType.cs
│ │ ├── PersonView.Properties.cs
│ │ ├── PersonView.cs
│ │ ├── PersonView.xaml
│ │ └── PersonViewType.cs
├── Converters
│ ├── ObjectToStringConverter.cs
│ └── UserToPersonConverter.cs
├── Extensions
│ └── ElementExtensions.IsVisibleWhen.cs
├── Properties
│ ├── AssemblyInfo.cs
│ └── CommunityToolkit.Uwp.Graph.Controls.rd.xml
├── Themes
│ └── Generic.xaml
├── Triggers
│ └── ProviderStateTrigger.cs
└── VisualStudioToolsManifest.xml
├── CommunityToolkit.Graph
├── CommunityToolkit.Graph.csproj
├── Extensions
│ ├── GraphExtensions.OneDrive.cs
│ ├── GraphExtensions.People.cs
│ ├── GraphExtensions.UserExtensions.cs
│ ├── GraphExtensions.Users.cs
│ ├── GraphExtensions.cs
│ └── ProviderExtensions.cs
└── Helpers
│ └── RoamingSettings
│ ├── OneDriveStorageHelper.cs
│ └── UserExtensionStorageHelper.cs
├── Directory.Build.props
├── Directory.Build.targets
├── LICENSE.md
├── README.md
├── SampleTest
├── App.xaml
├── App.xaml.cs
├── Assets
│ ├── FileIcon.png
│ ├── LockScreenLogo.scale-200.png
│ ├── SplashScreen.scale-200.png
│ ├── Square150x150Logo.scale-200.png
│ ├── Square44x44Logo.scale-200.png
│ ├── Square44x44Logo.targetsize-24_altform-unplated.png
│ ├── StoreLogo.png
│ └── Wide310x150Logo.scale-200.png
├── MainPage.xaml
├── MainPage.xaml.cs
├── Package.appxmanifest
├── Properties
│ ├── AssemblyInfo.cs
│ └── Default.rd.xml
├── SampleTest.csproj
└── Samples
│ ├── GraphPresenter
│ ├── CalendarViewSample.xaml
│ ├── CalendarViewSample.xaml.cs
│ ├── MailMessagesSample.xaml
│ ├── MailMessagesSample.xaml.cs
│ ├── OneDriveSample.xaml
│ ├── OneDriveSample.xaml.cs
│ ├── PlannerTasksSample.xaml
│ ├── PlannerTasksSample.xaml.cs
│ ├── TeamsChannelMessagesSample.xaml
│ └── TeamsChannelMessagesSample.xaml.cs
│ ├── GraphPresenterSample.xaml
│ ├── GraphPresenterSample.xaml.cs
│ ├── PeoplePickerSample.xaml
│ ├── PeoplePickerSample.xaml.cs
│ ├── PersonViewSample.xaml
│ └── PersonViewSample.xaml.cs
├── Samples
├── ManualGraphRequestSample
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── Assets
│ │ ├── LockScreenLogo.scale-200.png
│ │ ├── SplashScreen.scale-200.png
│ │ ├── Square150x150Logo.scale-200.png
│ │ ├── Square44x44Logo.scale-200.png
│ │ ├── Square44x44Logo.targetsize-24_altform-unplated.png
│ │ ├── StoreLogo.png
│ │ └── Wide310x150Logo.scale-200.png
│ ├── MainPage.xaml
│ ├── MainPage.xaml.cs
│ ├── ManualGraphRequestSample.csproj
│ ├── Models
│ │ └── TodoTask.cs
│ ├── Package.appxmanifest
│ └── Properties
│ │ ├── AssemblyInfo.cs
│ │ └── Default.rd.xml
├── UwpMsalProviderSample
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── Assets
│ │ ├── LockScreenLogo.scale-200.png
│ │ ├── SplashScreen.scale-200.png
│ │ ├── Square150x150Logo.scale-200.png
│ │ ├── Square44x44Logo.scale-200.png
│ │ ├── Square44x44Logo.targetsize-24_altform-unplated.png
│ │ ├── StoreLogo.png
│ │ └── Wide310x150Logo.scale-200.png
│ ├── MainPage.xaml
│ ├── MainPage.xaml.cs
│ ├── Package.appxmanifest
│ ├── Properties
│ │ ├── AssemblyInfo.cs
│ │ └── Default.rd.xml
│ ├── README.md
│ └── UwpMsalProviderSample.csproj
├── UwpWindowsProviderSample
│ ├── AccountManagerButton.xaml
│ ├── AccountManagerButton.xaml.cs
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── Assets
│ │ ├── LockScreenLogo.scale-200.png
│ │ ├── SplashScreen.scale-200.png
│ │ ├── Square150x150Logo.scale-200.png
│ │ ├── Square44x44Logo.scale-200.png
│ │ ├── Square44x44Logo.targetsize-24_altform-unplated.png
│ │ ├── StoreLogo.png
│ │ └── Wide310x150Logo.scale-200.png
│ ├── MainPage.xaml
│ ├── MainPage.xaml.cs
│ ├── Package.appxmanifest
│ ├── Properties
│ │ ├── AssemblyInfo.cs
│ │ └── Default.rd.xml
│ ├── README.md
│ └── UwpWindowsProviderSample.csproj
├── WpfNetCoreMsalProviderSample
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── AssemblyInfo.cs
│ ├── CacheConfig.cs
│ ├── LoginButton.xaml
│ ├── LoginButton.xaml.cs
│ ├── MainWindow.xaml
│ ├── MainWindow.xaml.cs
│ ├── README.md
│ └── WpfNetCoreMsalProviderSample.csproj
└── WpfNetWindowsMsalProviderSample
│ ├── App.xaml
│ ├── App.xaml.cs
│ ├── AssemblyInfo.cs
│ ├── CacheConfig.cs
│ ├── LoginButton.xaml
│ ├── LoginButton.xaml.cs
│ ├── MainWindow.xaml
│ ├── MainWindow.xaml.cs
│ ├── README.md
│ └── WpfNetWindowsMsalProviderSample.csproj
├── UnitTests
└── UnitTests.UWP
│ ├── Assets
│ ├── LockScreenLogo.scale-200.png
│ ├── SplashScreen.scale-200.png
│ ├── Square150x150Logo.scale-200.png
│ ├── Square44x44Logo.scale-200.png
│ ├── Square44x44Logo.targetsize-24_altform-unplated.png
│ ├── StoreLogo.png
│ └── Wide310x150Logo.scale-200.png
│ ├── Package.appxmanifest
│ ├── Properties
│ ├── AssemblyInfo.cs
│ └── Default.rd.xml
│ ├── Providers
│ ├── Test_MockProvider.cs
│ └── Test_WindowsProvider.cs
│ ├── RoamingSettings
│ ├── Test_OneDriveDataStore.cs
│ └── Test_UserExtensionDataStore.cs
│ ├── SmokeTest.cs
│ ├── UnitTestApp.xaml
│ ├── UnitTestApp.xaml.cs
│ ├── UnitTests.UWP.csproj
│ └── VisualUITestBase.cs
├── Windows-Toolkit-Graph-Controls.sln
├── azure-pipelines.yml
├── build
├── Find-WindowsSDKVersions.ps1
├── Install-WindowsSDK.ps1
├── Install-WindowsSdkISO.ps1
├── Sign-Package.ps1
├── SignClientSettings.json
├── Windows.Toolkit.Common.props
├── Windows.Toolkit.Common.targets
├── Windows.Toolkit.UWP.Build.targets
├── Windows.Toolkit.Workarounds.Xaml.targets
└── nuget.png
├── global.json
├── nuget.config
├── settings.xamlstyler
├── toolkit.public.snk
├── toolkit.snk
└── version.json
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us fix something that isn't working as expected
4 | title: ''
5 | labels: "bug :bug:"
6 | assignees: ''
7 |
8 | ---
9 |
10 |
14 |
15 | ## Describe the bug
16 | A clear and concise description of what the bug is.
17 |
18 | - [ ] Is this bug a regression in the toolkit? If so, what toolkit version did you last see it work:
19 |
20 | ## Steps to Reproduce
21 | Steps to reproduce the behavior:
22 | 1. Go to '...'
23 | 2. Click on '....'
24 | 3. Scroll down to '....'
25 | 4. See error
26 |
27 | ## Expected behavior
28 | A clear and concise description of what you expected to happen.
29 |
30 | ## Screenshots
31 | If applicable, add screenshots to help explain your problem.
32 |
33 | ## Environment
34 |
35 | ```
36 | NuGet Package(s):
37 |
38 | Package Version(s):
39 |
40 | Windows 10 Build Number:
41 | - [ ] Fall Creators Update (16299)
42 | - [ ] April 2018 Update (17134)
43 | - [ ] October 2018 Update (17763)
44 | - [ ] May 2019 Update (18362)
45 | - [ ] Insider Build (build number: )
46 |
47 | App min and target version:
48 | - [ ] Fall Creators Update (16299)
49 | - [ ] April 2018 Update (17134)
50 | - [ ] October 2018 Update (17763)
51 | - [ ] May 2019 Update (18362)
52 | - [ ] Insider Build (xxxxx)
53 |
54 | Device form factor:
55 | - [ ] Desktop
56 | - [ ] Xbox
57 | - [ ] Surface Hub
58 | - [ ] IoT
59 |
60 | Visual Studio
61 | - [ ] 2017 (version: )
62 | - [ ] 2019 (version: )
63 | - [ ] 2019 Preview (version: )
64 |
65 | ```
66 |
67 | ## Additional context
68 | Add any other context about the problem here.
69 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/documentation.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Documentation
3 | about: I have a documentation suggestion or question
4 | title: "[Docs]"
5 | labels: "documentation :page_with_curl:"
6 | assignees: ''
7 |
8 | ---
9 |
10 |
19 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: I have a new idea or improvement for the toolkit
4 | title: "[Feature]"
5 | labels: feature request 📬
6 | assignees: ''
7 |
8 | ---
9 |
10 | ## Describe the problem this feature would solve
11 |
13 |
14 | ## Describe the solution
15 |
16 |
17 | ## Describe alternatives you've considered
18 |
19 |
20 | ## Additional context & Screenshots
21 |
22 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/question.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Question
3 | about: I have a question about how to use something in the toolkit.
4 | title: "[Question]"
5 | labels: "question :grey_question:"
6 | assignees: ''
7 |
8 | ---
9 |
10 |
23 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | Fixes #
2 |
3 |
4 |
5 | ## PR Type
6 |
7 | What kind of change does this PR introduce?
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | ## What is the current behavior?
21 |
22 |
23 |
24 | ## What is the new behavior?
25 |
26 | ## PR Checklist
27 |
28 | Please check if your PR fulfills the following requirements:
29 |
30 | - [ ] Tested code with current [supported SDKs](https://github.com/CommunityToolkit/Graph-Controls/blob/main/README.md)
31 | - [ ] Sample in sample app has been added / updated (for bug fixes / features)
32 | - [ ] Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/CommunityToolkit/WindowsCommunityToolkit-design-assets)
33 | - [ ] Tests for the changes have been added (for bug fixes / features) (if applicable)
34 | - [ ] Header has been added to all new source files (run _build/UpdateHeaders.bat_)
35 | - [ ] Contains **NO** breaking changes
36 |
37 |
39 |
40 | ## Other information
41 |
--------------------------------------------------------------------------------
/CommunityToolkit.Authentication.Msal/CommunityToolkit.Authentication.Msal.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0;uap10.0.17763;net6.0-windows10.0.17763.0;netcoreapp3.1
5 | 10.0.17763.0
6 | 7
7 |
8 | Windows Community Toolkit .NET Standard Auth Services
9 |
10 | This library provides an authentication provider based on the native Windows dialogues. It is part of the Windows Community Toolkit.
11 |
12 | Classes:
13 | - MsalProvider: An authentication provider based on MSAL for .NET.
14 |
15 | Community Toolkit Provider Authentication Auth Msal
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/CommunityToolkit.Authentication.Msal/MsalProviderExtensions.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System.Diagnostics;
6 | using System.Threading.Tasks;
7 | using Microsoft.Identity.Client.Extensions.Msal;
8 |
9 | namespace CommunityToolkit.Authentication.Extensions
10 | {
11 | ///
12 | /// Helpers for working with the MsalProvider.
13 | ///
14 | public static class MsalProviderExtensions
15 | {
16 | ///
17 | /// Helper function to initialize the token cache for non-UWP apps. MSAL handles this automatically on UWP.
18 | ///
19 | /// The instance of to init the cache for.
20 | /// Properties for configuring the storage cache.
21 | /// Passing null uses the default TraceSource logger.
22 | /// A representing the result of the asynchronous operation.
23 | public static async Task InitTokenCacheAsync(
24 | this MsalProvider provider,
25 | StorageCreationProperties storageProperties,
26 | TraceSource logger = null)
27 | {
28 | #if !WINDOWS_UWP
29 | // Token cache persistence (not required on UWP as MSAL does it for you)
30 | var cacheHelper = await MsalCacheHelper.CreateAsync(storageProperties, logger);
31 | cacheHelper.RegisterCache(provider.Client.UserTokenCache);
32 | #endif
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/CommunityToolkit.Authentication.Uwp/AccountsSettingsPaneConfig.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System.Collections.Generic;
6 | using Windows.UI.ApplicationSettings;
7 |
8 | namespace CommunityToolkit.Authentication
9 | {
10 | ///
11 | /// Configuration values for the AccountsSettingsPane.
12 | ///
13 | public struct AccountsSettingsPaneConfig
14 | {
15 | ///
16 | /// Gets or sets the header text for the add accounts settings pane.
17 | ///
18 | public string AddAccountHeaderText { get; set; }
19 |
20 | ///
21 | /// Gets or sets the header text for the manage accounts settings pane.
22 | ///
23 | public string ManageAccountHeaderText { get; set; }
24 |
25 | ///
26 | /// Gets or sets the SettingsCommand collection for the account settings pane.
27 | ///
28 | public IList Commands { get; set; }
29 |
30 | ///
31 | /// Gets or sets the WebAccountCommandParameter for the account settings pane.
32 | ///
33 | public WebAccountCommandParameter AccountCommandParameter { get; set; }
34 |
35 | ///
36 | /// Initializes a new instance of the struct.
37 | ///
38 | /// The header text for the add accounts settings pane.
39 | /// The header text for the manage accounts settings pane.
40 | /// The SettingsCommand collection for the account settings pane.
41 | /// The WebAccountCommandParameter for the account settings pane.
42 | public AccountsSettingsPaneConfig(
43 | string addAccountHeaderText = null,
44 | string manageAccountHeaderText = null,
45 | IList commands = null,
46 | WebAccountCommandParameter accountCommandParameter = null)
47 | {
48 | AddAccountHeaderText = addAccountHeaderText;
49 | ManageAccountHeaderText = manageAccountHeaderText;
50 | Commands = commands;
51 | AccountCommandParameter = accountCommandParameter;
52 | }
53 | }
54 | }
--------------------------------------------------------------------------------
/CommunityToolkit.Authentication.Uwp/CommunityToolkit.Authentication.Uwp.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | uap10.0.17763
5 | Windows Community Toolkit Graph Uwp Authentication Provider
6 |
7 | This library provides an authentication provider based on the native Windows dialogues.
8 |
9 | Classes:
10 | - WindowsProvider: An authentication provider based on the native AccountsSettingsPane in Windows.
11 |
12 | UWP Community Toolkit Provider Authentication Auth Windows
13 | 10.0
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/CommunityToolkit.Authentication.Uwp/WebAccountCommandParameter.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using Windows.UI.ApplicationSettings;
6 |
7 | namespace CommunityToolkit.Authentication
8 | {
9 | ///
10 | /// can be produced through this parameter.
11 | ///
12 | public class WebAccountCommandParameter
13 | {
14 | ///
15 | /// Gets the delegate that's invoked when the user selects an account and a specific
16 | /// action in the account settings pane.
17 | ///
18 | public WebAccountCommandInvokedHandler Invoked { get; }
19 |
20 | ///
21 | /// Gets the actions that the command performs on the web account in the accounts pane.
22 | ///
23 | public SupportedWebAccountActions Actions { get; }
24 |
25 | ///
26 | /// Initializes a new instance of the class.
27 | ///
28 | /// The delegate that's invoked when the user selects an account and a specific
29 | /// action in the account settings pane.
30 | /// The actions that the command performs on the web account in the accounts pane.
31 | public WebAccountCommandParameter(WebAccountCommandInvokedHandler invoked, SupportedWebAccountActions actions)
32 | {
33 | Invoked = invoked;
34 | Actions = actions;
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/CommunityToolkit.Authentication.Uwp/WebAccountProviderConfig.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System.Collections.Generic;
6 |
7 | namespace CommunityToolkit.Authentication
8 | {
9 | ///
10 | /// Configuration values for what type of authentication providers to enable.
11 | ///
12 | public struct WebAccountProviderConfig
13 | {
14 | ///
15 | /// Gets or sets the registered ClientId. Required for AAD login and admin consent.
16 | ///
17 | public string ClientId { get; set; }
18 |
19 | ///
20 | /// Gets or sets the types of accounts providers that should be available to the user.
21 | ///
22 | public WebAccountProviderType WebAccountProviderType { get; set; }
23 |
24 | ///
25 | /// Gets or sets the properties that need to be added when constructing (for MSA).
26 | ///
27 | public IDictionary MSATokenRequestProperties { get; set; }
28 |
29 | ///
30 | /// Gets or sets the properties that need to be added when constructing (for AAD).
31 | ///
32 | public IDictionary AADTokenRequestProperties { get; set; }
33 |
34 | ///
35 | /// Initializes a new instance of the struct.
36 | ///
37 | /// The types of accounts providers that should be available to the user.
38 | /// The registered ClientId. Required for AAD login and admin consent.
39 | public WebAccountProviderConfig(WebAccountProviderType webAccountProviderType, string clientId = null)
40 | {
41 | WebAccountProviderType = webAccountProviderType;
42 | ClientId = clientId;
43 | MSATokenRequestProperties = new Dictionary();
44 | AADTokenRequestProperties = new Dictionary();
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/CommunityToolkit.Authentication.Uwp/WebAccountProviderType.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | namespace CommunityToolkit.Authentication
6 | {
7 | ///
8 | /// An enumeration of the available authentication providers for use in the AccountsSettingsPane.
9 | ///
10 | public enum WebAccountProviderType
11 | {
12 | ///
13 | /// Authenticate any available accounts.
14 | /// Store app association required to support consumer accounts.
15 | /// Client ID required to support organizational accounts.
16 | ///
17 | Any,
18 |
19 | ///
20 | /// Authenticate consumer MSA accounts. Store app association required.
21 | ///
22 | Msa,
23 |
24 | ///
25 | /// Authenticate organizational AAD accounts. Client ID required.
26 | ///
27 | Aad,
28 |
29 | ///
30 | /// Authenticate the active local account regardles of type (consumer/organizational).
31 | /// Store app association required to support consumer accounts.
32 | /// Client ID required to support organizational accounts.
33 | ///
34 | Local,
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/CommunityToolkit.Authentication/BaseProvider.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System;
6 | using System.Net.Http;
7 | using System.Threading.Tasks;
8 | using CommunityToolkit.Authentication.Extensions;
9 |
10 | namespace CommunityToolkit.Authentication
11 | {
12 | ///
13 | /// A base construct for building Graph Providers on top of.
14 | ///
15 | public abstract class BaseProvider : IProvider
16 | {
17 | private ProviderState _state;
18 |
19 | ///
20 | /// Gets or sets the current state of the provider.
21 | ///
22 | public ProviderState State
23 | {
24 | get => _state;
25 | protected set
26 | {
27 | var oldState = _state;
28 | var newState = value;
29 | if (oldState != newState)
30 | {
31 | _state = newState;
32 | StateChanged?.Invoke(this, new ProviderStateChangedEventArgs(oldState, newState));
33 | }
34 | }
35 | }
36 |
37 | ///
38 | public abstract string CurrentAccountId { get; }
39 |
40 | ///
41 | public event EventHandler StateChanged;
42 |
43 | ///
44 | /// Initializes a new instance of the class.
45 | ///
46 | public BaseProvider()
47 | {
48 | _state = ProviderState.Loading;
49 | }
50 |
51 | ///
52 | public abstract Task AuthenticateRequestAsync(HttpRequestMessage request);
53 |
54 | ///
55 | public abstract Task GetTokenAsync(bool silentOnly = false);
56 |
57 | ///
58 | public abstract Task SignInAsync();
59 |
60 | ///
61 | public abstract Task SignOutAsync();
62 |
63 | ///
64 | public abstract Task TrySilentSignInAsync();
65 |
66 | ///
67 | /// Append the Sdk version to the request headers.
68 | ///
69 | ///
70 | /// The request to append the header to.
71 | ///
72 | protected void AddSdkVersion(HttpRequestMessage request)
73 | {
74 | request.AddSdkVersion();
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/CommunityToolkit.Authentication/CommunityToolkit.Authentication.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | netstandard2.0
4 |
5 | Windows Community Toolkit .NET Standard Auth Services
6 |
7 | This package includes .NET Standard authentication helpers such as:
8 |
9 | - BaseProvider: A base construct for building Graph Providers on top of.
10 | - IProvider: Authentication provider interface to expose more states around the authentication process for Graph controls and helpers.
11 | - ProviderManager: Shared provider manager used by controls and helpers to authenticate and call the Microsoft Graph.
12 | - ProviderState: Represents the current authentication state of the session for a given IProvider.
13 |
14 | Community Toolkit Provider Authentication Auth
15 |
16 |
17 |
--------------------------------------------------------------------------------
/CommunityToolkit.Authentication/Extensions/HttpRequestMessageExtensions.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Net.Http;
8 | using System.Net.Http.Headers;
9 | using System.Reflection;
10 | using System.Threading.Tasks;
11 |
12 | namespace CommunityToolkit.Authentication.Extensions
13 | {
14 | ///
15 | /// Helpers for Graph related HTTP Headers.
16 | ///
17 | public static class HttpRequestMessageExtensions
18 | {
19 | private const string SdkVersion = "SdkVersion";
20 | private const string LibraryName = "wct";
21 | private const string Bearer = "Bearer";
22 | private const string MockGraphToken = "{token:https://graph.microsoft.com/}";
23 |
24 | internal static void AddSdkVersion(this HttpRequestMessage request)
25 | {
26 | if (request == null || request.Headers == null)
27 | {
28 | return;
29 | }
30 |
31 | if (request.Headers.TryGetValues(SdkVersion, out IEnumerable values))
32 | {
33 | var versions = new List(values);
34 | versions.Insert(0, LibraryName + "/" + Assembly.GetExecutingAssembly().GetName().Version);
35 | request.Headers.Remove(SdkVersion);
36 | request.Headers.Add(SdkVersion, versions);
37 | }
38 | }
39 |
40 | internal static void AddMockProviderToken(this HttpRequestMessage request)
41 | {
42 | request
43 | .Headers
44 | .Authorization = new AuthenticationHeaderValue(Bearer, MockGraphToken);
45 | }
46 |
47 | ///
48 | /// Helper method for authenticating an http request using the GlobalProvider instance.
49 | ///
50 | /// The request to authenticate.
51 | /// A task upon completion.
52 | public static async Task AuthenticateAsync(this HttpRequestMessage request)
53 | {
54 | if (ProviderManager.Instance.GlobalProvider == null)
55 | {
56 | throw new InvalidOperationException("The request cannot be authenticated. The GlobalProvider is null.");
57 | }
58 |
59 | await ProviderManager.Instance.GlobalProvider.AuthenticateRequestAsync(request);
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/CommunityToolkit.Authentication/IProvider.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System;
6 | using System.Net.Http;
7 | using System.Threading.Tasks;
8 |
9 | namespace CommunityToolkit.Authentication
10 | {
11 | ///
12 | /// Authentication provider to expose more states around the authentication process for graph controls.
13 | ///
14 | public interface IProvider
15 | {
16 | ///
17 | /// Gets the current login state of the provider.
18 | ///
19 | ProviderState State { get; }
20 |
21 | ///
22 | /// Gets the id of the currently signed in user account.
23 | ///
24 | string CurrentAccountId { get; }
25 |
26 | ///
27 | /// Event called when the login changes.
28 | ///
29 | event EventHandler StateChanged;
30 |
31 | ///
32 | /// Authenticate an outgoing request.
33 | ///
34 | /// The request to authenticate.
35 | /// A task upon completion.
36 | Task AuthenticateRequestAsync(HttpRequestMessage request);
37 |
38 | ///
39 | /// Retrieve a token for the authenticated user.
40 | ///
41 | /// Determines if the acquisition should be done without prompts to the user.
42 | /// A token string for the authenticated user.
43 | Task GetTokenAsync(bool silentOnly = false);
44 |
45 | ///
46 | /// Sign in the user.
47 | ///
48 | /// .
49 | Task SignInAsync();
50 |
51 | ///
52 | /// Sign out the user.
53 | ///
54 | /// .
55 | Task SignOutAsync();
56 |
57 | ///
58 | /// Tries to check if the user is logged in without prompting to login.
59 | ///
60 | /// A boolean indicating success or failure to sign in silently.
61 | Task TrySilentSignInAsync();
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/CommunityToolkit.Authentication/ProviderManager.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System;
6 | using System.ComponentModel;
7 |
8 | namespace CommunityToolkit.Authentication
9 | {
10 | ///
11 | /// Shared provider manager used by controls and helpers to authenticate and call the Microsoft Graph.
12 | ///
13 | /// To set your own existing provider:
14 | ///
15 | /// ProviderManager.Instance.GlobalProvider = await new MsalProvider(clientId, scopes);
16 | ///
17 | ///
18 | public partial class ProviderManager : INotifyPropertyChanged
19 | {
20 | ///
21 | /// Gets the name of the toolkit client to identify self in Graph calls.
22 | ///
23 | public static readonly string ClientName = "wct/" + ThisAssembly.AssemblyVersion;
24 |
25 | ///
26 | /// Gets the instance of the GlobalProvider.
27 | ///
28 | public static ProviderManager Instance { get; } = new ProviderManager();
29 |
30 | ///
31 | /// Event called when the instance changes.
32 | ///
33 | public event EventHandler ProviderUpdated;
34 |
35 | ///
36 | /// Event called when the state changes.
37 | ///
38 | public event EventHandler ProviderStateChanged;
39 |
40 | ///
41 | public event PropertyChangedEventHandler PropertyChanged;
42 |
43 | ///
44 | /// Gets or sets the global provider used by all Microsoft.Toolkit.Graph.Controls.
45 | ///
46 | public IProvider GlobalProvider
47 | {
48 | get
49 | {
50 | return _provider;
51 | }
52 |
53 | set
54 | {
55 | var oldState = _provider?.State;
56 | if (_provider != null)
57 | {
58 | _provider.StateChanged -= OnProviderStateChanged;
59 | }
60 |
61 | _provider = value;
62 |
63 | var newState = _provider?.State;
64 | if (_provider != null)
65 | {
66 | _provider.StateChanged += OnProviderStateChanged;
67 | }
68 |
69 | ProviderUpdated?.Invoke(this, _provider);
70 | ProviderStateChanged?.Invoke(this, new ProviderStateChangedEventArgs(oldState, newState));
71 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(GlobalProvider)));
72 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(State)));
73 | }
74 | }
75 |
76 | ///
77 | /// Gets the ProviderState of the current GlobalProvider instance.
78 | /// Use for binding scenarios instead of ProviderManager.Instance.GlobalProvider.State.
79 | ///
80 | public ProviderState? State => GlobalProvider?.State;
81 |
82 | private IProvider _provider;
83 |
84 | private ProviderManager()
85 | {
86 | // Use Instance
87 | }
88 |
89 | private void OnProviderStateChanged(object sender, ProviderStateChangedEventArgs args)
90 | {
91 | ProviderStateChanged?.Invoke(this, args);
92 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(State)));
93 | }
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/CommunityToolkit.Authentication/ProviderState.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | namespace CommunityToolkit.Authentication
6 | {
7 | ///
8 | /// represents the current authentication state of the session for a given .
9 | ///
10 | public enum ProviderState
11 | {
12 | ///
13 | /// The user's status is not known.
14 | ///
15 | Loading,
16 |
17 | ///
18 | /// The user is signed-out.
19 | ///
20 | SignedOut,
21 |
22 | ///
23 | /// The user is signed-in.
24 | ///
25 | SignedIn,
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/CommunityToolkit.Authentication/ProviderStateChangedEventArgs.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System;
6 |
7 | namespace CommunityToolkit.Authentication
8 | {
9 | ///
10 | /// event arguments.
11 | ///
12 | public class ProviderStateChangedEventArgs : EventArgs
13 | {
14 | ///
15 | /// Initializes a new instance of the class.
16 | ///
17 | /// Previous .
18 | /// Current .
19 | public ProviderStateChangedEventArgs(ProviderState? oldState, ProviderState? newState)
20 | {
21 | OldState = oldState;
22 | NewState = newState;
23 | }
24 |
25 | ///
26 | /// Gets the previous state of the .
27 | ///
28 | public ProviderState? OldState { get; private set; }
29 |
30 | ///
31 | /// Gets the new state of the .
32 | ///
33 | public ProviderState? NewState { get; private set; }
34 | }
35 | }
--------------------------------------------------------------------------------
/CommunityToolkit.Graph.Uwp/Assets/person.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/CommunityToolkit.Graph.Uwp/Assets/person.png
--------------------------------------------------------------------------------
/CommunityToolkit.Graph.Uwp/CommunityToolkit.Graph.Uwp.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | uap10.0.17763
5 | Windows Community Toolkit Graph Uwp Controls and Helpers
6 |
7 | This library provides Microsoft Graph UWP XAML controls. It is part of the Windows Community Toolkit.
8 |
9 | Controls:
10 | - GraphPresenter: A specialized ContentPresenter for fetching and displaying data from Microsoft Graph.
11 | - LoginButton: The Login Control leverages the global authentication provider to support the sign-in processes for Microsoft Graph and beyond.
12 | - PersonView: The PersonView control displays a user photo and can display their name and e-mail.
13 | - PeoplePicker: The PeoplePicker Control is a simple control that allows for selection users.
14 |
15 | Extensions:
16 | - FrameworkElement.IsVisibleWhen(ProviderState): Extension on FrameworkElement for toggling visibility in response to changes in the global authentcation provider.
17 |
18 | Triggers:
19 | - ProviderStateTrigger: StateTrigger for reacting to changes in the global authentcation provider.
20 |
21 | UWP Community Toolkit Windows Controls Microsoft Graph Login Person PeoplePicker Presenter
22 | 10.0
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/CommunityToolkit.Graph.Uwp/Controls/GraphPresenter/QueryOption.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 | using Windows.Foundation.Metadata;
11 | using Windows.UI.Xaml;
12 |
13 | namespace CommunityToolkit.Graph.Uwp.Controls
14 | {
15 | ///
16 | /// XAML Proxy for .
17 | ///
18 | [Experimental]
19 | public sealed class QueryOption
20 | {
21 | ///
22 | public string Name { get; set; }
23 |
24 | ///
25 | public string Value { get; set; }
26 |
27 | ///
28 | /// Implicit conversion for to .
29 | ///
30 | /// query option to convert.
31 | public static implicit operator Microsoft.Graph.QueryOption(QueryOption option)
32 | {
33 | return new Microsoft.Graph.QueryOption(option.Name, option.Value);
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/CommunityToolkit.Graph.Uwp/Controls/LoginButton/LoginButton.Events.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System;
6 | using System.ComponentModel;
7 |
8 | namespace CommunityToolkit.Graph.Uwp.Controls
9 | {
10 | ///
11 | /// The control is a button which can be used to sign the user in or show them profile details.
12 | ///
13 | public partial class LoginButton
14 | {
15 | ///
16 | /// The user clicked the sign in button to start the login process - cancelable.
17 | ///
18 | public event CancelEventHandler LoginInitiated;
19 |
20 | ///
21 | /// The login process was successful and the user is now signed in.
22 | ///
23 | public event EventHandler LoginCompleted;
24 |
25 | ///
26 | /// The user canceled the login process or was unable to sign in.
27 | ///
28 | public event EventHandler LoginFailed;
29 |
30 | ///
31 | /// The user started to logout - cancelable.
32 | ///
33 | public event CancelEventHandler LogoutInitiated;
34 |
35 | ///
36 | /// The user signed out.
37 | ///
38 | public event EventHandler LogoutCompleted;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/CommunityToolkit.Graph.Uwp/Controls/LoginButton/LoginButton.Properties.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using Microsoft.Graph;
6 | using Windows.UI.Xaml;
7 |
8 | namespace CommunityToolkit.Graph.Uwp.Controls
9 | {
10 | ///
11 | /// The control is a button which can be used to sign the user in or show them profile details.
12 | ///
13 | public partial class LoginButton
14 | {
15 | ///
16 | /// Gets or sets details about this person retrieved from the graph or provided by the developer.
17 | ///
18 | public User UserDetails
19 | {
20 | get { return (User)GetValue(UserDetailsProperty); }
21 | protected set { SetValue(UserDetailsProperty, value); }
22 | }
23 |
24 | ///
25 | /// Identifies the dependency property.
26 | ///
27 | ///
28 | /// The identifier for the dependency property.
29 | ///
30 | public static readonly DependencyProperty UserDetailsProperty =
31 | DependencyProperty.Register(nameof(UserDetails), typeof(User), typeof(LoginButton), new PropertyMetadata(null));
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/CommunityToolkit.Graph.Uwp/Controls/LoginButton/LoginButton.xaml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
12 |
13 |
14 |
59 |
60 |
--------------------------------------------------------------------------------
/CommunityToolkit.Graph.Uwp/Controls/LoginButton/LoginFailedEventArgs.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System;
6 |
7 | namespace CommunityToolkit.Graph.Uwp.Controls
8 | {
9 | ///
10 | /// for event.
11 | ///
12 | public class LoginFailedEventArgs : EventArgs
13 | {
14 | ///
15 | /// Gets the exception which occured during login.
16 | ///
17 | public Exception Exception { get; private set; }
18 |
19 | ///
20 | /// Gets the inner exception which occured during login.
21 | ///
22 | public Exception InnerException
23 | {
24 | get
25 | {
26 | return Exception?.InnerException;
27 | }
28 | }
29 |
30 | ///
31 | /// Gets the error message of the inner error or error.
32 | ///
33 | public string Message
34 | {
35 | get
36 | {
37 | return Exception?.InnerException?.Message ?? Exception?.Message;
38 | }
39 | }
40 |
41 | ///
42 | /// Initializes a new instance of the class.
43 | ///
44 | /// Exception encountered during login.
45 | public LoginFailedEventArgs(Exception exception)
46 | {
47 | Exception = exception;
48 | }
49 | }
50 | }
--------------------------------------------------------------------------------
/CommunityToolkit.Graph.Uwp/Controls/PeoplePicker/PeoplePicker.xaml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
8 |
10 |
11 |
39 |
40 |
--------------------------------------------------------------------------------
/CommunityToolkit.Graph.Uwp/Controls/PersonView/PersonAvatarType.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | namespace CommunityToolkit.Graph.Uwp.Controls
6 | {
7 | ///
8 | /// The type of visual representation to use for the person.
9 | ///
10 | public enum PersonAvatarType
11 | {
12 | ///
13 | /// Show a user's photo if available, otherwise show initials.
14 | ///
15 | Photo,
16 |
17 | ///
18 | /// Show the user's initials only.
19 | ///
20 | Initials,
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/CommunityToolkit.Graph.Uwp/Controls/PersonView/PersonViewType.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | namespace CommunityToolkit.Graph.Uwp.Controls
6 | {
7 | ///
8 | /// Enumeration of what details should be displayed in a PersonView.
9 | ///
10 | public enum PersonViewType
11 | {
12 | ///
13 | /// Render only the avatar.
14 | ///
15 | Avatar = 0,
16 |
17 | ///
18 | /// Render the avatar and one line of text.
19 | ///
20 | OneLine = 1,
21 |
22 | ///
23 | /// Render the avatar and two lines of text.
24 | ///
25 | TwoLines = 2,
26 |
27 | ///
28 | /// Render the avatar and three lines of text.
29 | ///
30 | ThreeLines = 3,
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/CommunityToolkit.Graph.Uwp/Converters/ObjectToStringConverter.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System;
6 | using Windows.UI.Xaml.Data;
7 |
8 | namespace CommunityToolkit.Graph.Uwp.Converters
9 | {
10 | ///
11 | /// Converts any object to a string representation.
12 | ///
13 | public class ObjectToStringConverter : IValueConverter
14 | {
15 | ///
16 | public object Convert(object value, Type targetType, object parameter, string language)
17 | {
18 | return value.ToString();
19 | }
20 |
21 | ///
22 | public object ConvertBack(object value, Type targetType, object parameter, string language)
23 | {
24 | throw new NotImplementedException();
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/CommunityToolkit.Graph.Uwp/Converters/UserToPersonConverter.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System;
6 | using CommunityToolkit.Graph.Extensions;
7 | using Microsoft.Graph;
8 | using Windows.UI.Xaml.Data;
9 |
10 | namespace CommunityToolkit.Graph.Uwp.Converters
11 | {
12 | ///
13 | /// Converts a to a .
14 | ///
15 | public class UserToPersonConverter : IValueConverter
16 | {
17 | ///
18 | public object Convert(object value, Type targetType, object parameter, string language)
19 | {
20 | if (value is User user)
21 | {
22 | return user.ToPerson();
23 | }
24 |
25 | return null;
26 | }
27 |
28 | ///
29 | public object ConvertBack(object value, Type targetType, object parameter, string language)
30 | {
31 | throw new NotImplementedException();
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/CommunityToolkit.Graph.Uwp/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System.Resources;
6 | using System.Runtime.CompilerServices;
7 |
8 | // General Information about an assembly is controlled through the following
9 | // set of attributes. Change these attribute values to modify the information
10 | // associated with an assembly.
11 | [assembly: NeutralResourcesLanguage("en-US")]
--------------------------------------------------------------------------------
/CommunityToolkit.Graph.Uwp/Properties/CommunityToolkit.Uwp.Graph.Controls.rd.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/CommunityToolkit.Graph.Uwp/Themes/Generic.xaml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/CommunityToolkit.Graph.Uwp/Triggers/ProviderStateTrigger.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using CommunityToolkit.Authentication;
6 | using Microsoft.Toolkit.Uwp;
7 | using Microsoft.Toolkit.Uwp.Helpers;
8 | using Windows.System;
9 | using Windows.UI.Xaml;
10 |
11 | namespace CommunityToolkit.Graph.Uwp
12 | {
13 | ///
14 | /// A StateTrigger for detecting when the global authentication provider has been signed in.
15 | ///
16 | public class ProviderStateTrigger : StateTriggerBase
17 | {
18 | ///
19 | /// Identifies the DependencyProperty.
20 | ///
21 | public static readonly DependencyProperty StateProperty =
22 | DependencyProperty.Register(nameof(State), typeof(ProviderState), typeof(ProviderStateTrigger), new PropertyMetadata(null, OnStateChanged));
23 |
24 | private static void OnStateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
25 | {
26 | if (d is ProviderStateTrigger instance)
27 | {
28 | instance.UpdateState();
29 | }
30 | }
31 |
32 | private readonly DispatcherQueue _dispatcherQueue;
33 |
34 | ///
35 | /// Gets or sets the expected ProviderState.
36 | ///
37 | public ProviderState? State
38 | {
39 | get => (ProviderState?)GetValue(StateProperty);
40 | set => SetValue(StateProperty, value);
41 | }
42 |
43 | ///
44 | /// Initializes a new instance of the class.
45 | ///
46 | public ProviderStateTrigger()
47 | {
48 | _dispatcherQueue = DispatcherQueue.GetForCurrentThread();
49 | var weakEvent =
50 | new WeakEventListener(this)
51 | {
52 | OnEventAction = (instance, source, args) => OnProviderStateChanged(source, args),
53 | OnDetachAction = (weakEventListener) => ProviderManager.Instance.ProviderStateChanged -= weakEventListener.OnEvent,
54 | };
55 | ProviderManager.Instance.ProviderStateChanged += weakEvent.OnEvent;
56 | UpdateState();
57 | }
58 |
59 | private void OnProviderStateChanged(object sender, ProviderStateChangedEventArgs e)
60 | {
61 | _ = _dispatcherQueue.EnqueueAsync(UpdateState, DispatcherQueuePriority.Normal);
62 | }
63 |
64 | private void UpdateState()
65 | {
66 | var provider = ProviderManager.Instance.GlobalProvider;
67 | if (State != null && provider?.State != null)
68 | {
69 | SetActive(provider?.State == State);
70 | }
71 | else
72 | {
73 | SetActive(false);
74 | }
75 | }
76 | }
77 | }
--------------------------------------------------------------------------------
/CommunityToolkit.Graph.Uwp/VisualStudioToolsManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/CommunityToolkit.Graph/CommunityToolkit.Graph.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 |
6 | Windows Community Toolkit .NET Standard Graph Services
7 |
8 | This package includes .NET Standard code helpers such as:
9 |
10 | Extensions:
11 | - GraphExtensions: Helpers for common tasks related to the Microsoft Graph in context of the available controls and helpers.
12 | - ProviderExtensions: Extension on IProvider for accessing a pre-configured GraphServiceClient instance.
13 |
14 | Helpers:
15 | - OneDriveStorageHelper: A helper for interacting with data stored via files and folders in OneDrive.
16 | - UserExtensionStorageHelper: A helper for interacting with open extensions on the Graph User to store data in key/value pairs.
17 |
18 | Windows Community Toolkit Microsoft Graph Provider Extensions Helpers Roaming Settings
19 | 10.0
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/CommunityToolkit.Graph/Extensions/GraphExtensions.People.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System.Threading.Tasks;
6 | using Microsoft.Graph;
7 |
8 | namespace CommunityToolkit.Graph.Extensions
9 | {
10 | ///
11 | /// People focused extension methods to the Graph SDK used by the controls and helpers.
12 | ///
13 | public static partial class GraphExtensions
14 | {
15 | ///
16 | /// Shortcut to perform a person query.
17 | ///
18 | /// Instance of the .
19 | /// User to search for.
20 | /// collection of .
21 | public static async Task FindPersonAsync(this GraphServiceClient graph, string query)
22 | {
23 | return await graph
24 | .Me
25 | .People
26 | .Request()
27 | .Search(query)
28 | .WithScopes(new string[] { "people.read" })
29 | .GetAsync();
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/CommunityToolkit.Graph/Extensions/GraphExtensions.Users.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System.IO;
6 | using System.Threading.Tasks;
7 | using Microsoft.Graph;
8 |
9 | namespace CommunityToolkit.Graph.Extensions
10 | {
11 | ///
12 | /// User focused extension methods to the Graph SDK used by the controls and helpers.
13 | ///
14 | public static partial class GraphExtensions
15 | {
16 | ///
17 | /// Retrieve the current user.
18 | ///
19 | /// Instance of the .
20 | /// A representing the asynchronous operation.
21 | public static async Task GetMeAsync(this GraphServiceClient graph)
22 | {
23 | return await graph
24 | .Me
25 | .Request()
26 | .WithScopes(new string[] { "user.read" })
27 | .GetAsync();
28 | }
29 |
30 | ///
31 | /// Retrieve a user by id.
32 | ///
33 | /// Instance of the .
34 | /// The is of the user to retrieve.
35 | /// A representing the asynchronous operation.
36 | public static async Task GetUserAsync(this GraphServiceClient graph, string userId)
37 | {
38 | return await graph
39 | .Users[userId]
40 | .Request()
41 | .WithScopes(new string[] { "user.read" })
42 | .GetAsync();
43 | }
44 |
45 | ///
46 | /// Shortcut to perform a user query.
47 | ///
48 | /// Instance of the .
49 | /// User to search for.
50 | /// collection of .
51 | public static async Task FindUserAsync(this GraphServiceClient graph, string query)
52 | {
53 | return await graph
54 | .Users
55 | .Request()
56 | .Filter($"startswith(displayName, '{query}') or startswith(givenName, '{query}') or startswith(surname, '{query}') or startswith(mail, '{query}') or startswith(userPrincipalName, '{query}')")
57 | .WithScopes(new string[] { "user.readbasic.all" })
58 | .GetAsync();
59 | }
60 |
61 | ///
62 | /// Helper to get the photo of a particular user.
63 | ///
64 | /// Instance of the .
65 | /// UserID.
66 | /// Stream with user photo or null.
67 | public static async Task GetUserPhoto(this GraphServiceClient graph, string userId)
68 | {
69 | return await graph
70 | .Users[userId]
71 | .Photo
72 | .Content
73 | .Request()
74 | .WithScopes(new string[] { "user.read" })
75 | .GetAsync();
76 | }
77 |
78 | ///
79 | /// Get the photo of the current user.
80 | ///
81 | /// Instance of the .
82 | /// Stream with user photo or null.
83 | public static async Task GetMyPhotoAsync(this GraphServiceClient graph)
84 | {
85 | return await graph
86 | .Me
87 | .Photo
88 | .Content
89 | .Request()
90 | .WithScopes(new string[] { "user.read" })
91 | .GetAsync();
92 | }
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/CommunityToolkit.Graph/Extensions/GraphExtensions.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using Microsoft.Graph;
6 |
7 | namespace CommunityToolkit.Graph.Extensions
8 | {
9 | ///
10 | /// Extension methods to the Graph SDK used by the controls and helpers.
11 | ///
12 | public static partial class GraphExtensions
13 | {
14 | ///
15 | /// Simple method to convert a to a with basic common properties like , , , , and intact.
16 | ///
17 | /// instance to convert.
18 | /// A new basic representation of that user.
19 | public static Person ToPerson(this User user)
20 | {
21 | return new Person()
22 | {
23 | // Primary Id
24 | Id = user.Id,
25 | UserPrincipalName = user.UserPrincipalName,
26 |
27 | // Standard User Info
28 | DisplayName = user.DisplayName,
29 | ScoredEmailAddresses = new ScoredEmailAddress[]
30 | {
31 | new ScoredEmailAddress()
32 | {
33 | Address = user.Mail ?? user.UserPrincipalName,
34 | },
35 | },
36 | GivenName = user.GivenName,
37 | Surname = user.Surname,
38 |
39 | // Company Information
40 | CompanyName = user.CompanyName,
41 | Department = user.Department,
42 | JobTitle = user.JobTitle,
43 | OfficeLocation = user.OfficeLocation,
44 | };
45 | }
46 |
47 | ///
48 | /// Extension to provider Searching on OData Requests.
49 | ///
50 | /// type.
51 | /// Request chain.
52 | /// Query to add for searching in QueryOptions.
53 | /// Same type.
54 | public static T Search(this T request, string query)
55 | where T : IBaseRequest
56 | {
57 | // Need quotes around query for e-mail searches: https://docs.microsoft.com/en-us/graph/people-example#perform-a-fuzzy-search
58 | request.QueryOptions?.Add(new QueryOption("$search", '"' + query + '"'));
59 |
60 | return request;
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/CommunityToolkit.Graph/Extensions/ProviderExtensions.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using CommunityToolkit.Authentication;
6 | using Microsoft.Graph;
7 |
8 | namespace CommunityToolkit.Graph.Extensions
9 | {
10 | ///
11 | /// Extension method for enabled Graph client access from an IProvider implementation.
12 | ///
13 | public static class ProviderExtensions
14 | {
15 | ///
16 | /// Gets a GraphServiceClient instance based on the current GlobalProvider.
17 | ///
18 | /// The provider for authenticating Graph calls.
19 | /// A GraphServiceClient instance.
20 | public static GraphServiceClient GetClient(this IProvider provider)
21 | {
22 | return new GraphServiceClient(new DelegateAuthenticationProvider(async (requestMessage) =>
23 | {
24 | await provider.AuthenticateRequestAsync(requestMessage);
25 | }));
26 | }
27 |
28 | ///
29 | /// Gets a GraphServiceClient instance based on the current GlobalProvider, but configured for the beta endpoint.
30 | ///
31 | /// The provider for authenticating Graph calls.
32 | /// A GraphServiceClient instance configured for the beta endpoint.
33 | public static GraphServiceClient GetBetaClient(this IProvider provider)
34 | {
35 | return new GraphServiceClient("https://graph.microsoft.com/beta", new DelegateAuthenticationProvider(async (requestMessage) =>
36 | {
37 | await provider.AuthenticateRequestAsync(requestMessage);
38 | }));
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildThisFileDirectory)
5 | $(RepositoryDirectory)build\
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | true
14 | $(RepositoryDirectory)bin\nupkg
15 | true
16 |
17 |
18 |
19 |
20 |
21 | false
22 | false
23 | $(NoWarn);CS8002;SA0001
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | $(NoWarn);CS8002
33 |
34 | true
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | true
48 |
49 | true
50 |
51 | $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/Directory.Build.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | true
7 | false
8 |
9 |
10 |
11 |
12 |
13 | true
14 | $(MSBuildThisFileDirectory)toolkit.snk
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | <_Parameter1>CommitHash
27 | <_Parameter2>$(SourceRevisionId)
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | # Windows Community Toolkit
2 |
3 | Copyright (c) .NET Foundation and Contributors
4 |
5 | All rights reserved.
6 |
7 | # MIT License (MIT)
8 |
9 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
14 |
--------------------------------------------------------------------------------
/SampleTest/App.xaml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
--------------------------------------------------------------------------------
/SampleTest/App.xaml.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System;
6 | using CommunityToolkit.Authentication;
7 | using Windows.ApplicationModel;
8 | using Windows.ApplicationModel.Activation;
9 | using Windows.UI.Xaml;
10 | using Windows.UI.Xaml.Controls;
11 | using Windows.UI.Xaml.Navigation;
12 |
13 | namespace SampleTest
14 | {
15 | sealed partial class App : Application
16 | {
17 | public App()
18 | {
19 | this.InitializeComponent();
20 | }
21 |
22 | // List of available authentication providers.
23 | private enum ProviderType
24 | {
25 | Mock,
26 | Msal,
27 | Windows
28 | }
29 |
30 | // Which provider should be used for authentication?
31 | private readonly ProviderType _providerType = ProviderType.Mock;
32 |
33 | ///
34 | /// Initialize the global authentication provider.
35 | ///
36 | private void InitializeGlobalProvider()
37 | {
38 | if (ProviderManager.Instance.GlobalProvider != null)
39 | {
40 | return;
41 | }
42 |
43 | // Provider config
44 | string clientId = "YOUR_CLIENT_ID_HERE";
45 | string[] scopes = { "User.Read", "User.ReadBasic.All", "People.Read", "Calendars.Read", "Mail.Read", "Group.Read.All", "ChannelMessage.Read.All" };
46 | bool autoSignIn = true;
47 |
48 | switch (_providerType)
49 | {
50 | // Mock provider
51 | case ProviderType.Mock:
52 | ProviderManager.Instance.GlobalProvider = new MockProvider(signedIn: autoSignIn);
53 | break;
54 |
55 | // Msal provider
56 | case ProviderType.Msal:
57 | ProviderManager.Instance.GlobalProvider = new MsalProvider(clientId: clientId, scopes: scopes, autoSignIn: autoSignIn);
58 | break;
59 |
60 | // Windows provider
61 | case ProviderType.Windows:
62 | var webAccountProviderConfig = new WebAccountProviderConfig(WebAccountProviderType.Msa, clientId);
63 | ProviderManager.Instance.GlobalProvider = new WindowsProvider(scopes, webAccountProviderConfig: webAccountProviderConfig, autoSignIn: autoSignIn);
64 | break;
65 | }
66 | }
67 |
68 | ///
69 | /// Invoked when the application is launched normally by the end user. Other entry points
70 | /// will be used such as when the application is launched to open a specific file.
71 | ///
72 | /// Details about the launch request and process.
73 | protected override void OnLaunched(LaunchActivatedEventArgs e)
74 | {
75 | Frame rootFrame = Window.Current.Content as Frame;
76 | if (rootFrame == null)
77 | {
78 | rootFrame = new Frame();
79 | Window.Current.Content = rootFrame;
80 | }
81 |
82 | if (e.PrelaunchActivated == false)
83 | {
84 | if (rootFrame.Content == null)
85 | {
86 | rootFrame.Navigate(typeof(MainPage), e.Arguments);
87 | }
88 |
89 | Window.Current.Activate();
90 |
91 | InitializeGlobalProvider();
92 | }
93 | }
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/SampleTest/Assets/FileIcon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/SampleTest/Assets/FileIcon.png
--------------------------------------------------------------------------------
/SampleTest/Assets/LockScreenLogo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/SampleTest/Assets/LockScreenLogo.scale-200.png
--------------------------------------------------------------------------------
/SampleTest/Assets/SplashScreen.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/SampleTest/Assets/SplashScreen.scale-200.png
--------------------------------------------------------------------------------
/SampleTest/Assets/Square150x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/SampleTest/Assets/Square150x150Logo.scale-200.png
--------------------------------------------------------------------------------
/SampleTest/Assets/Square44x44Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/SampleTest/Assets/Square44x44Logo.scale-200.png
--------------------------------------------------------------------------------
/SampleTest/Assets/Square44x44Logo.targetsize-24_altform-unplated.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/SampleTest/Assets/Square44x44Logo.targetsize-24_altform-unplated.png
--------------------------------------------------------------------------------
/SampleTest/Assets/StoreLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/SampleTest/Assets/StoreLogo.png
--------------------------------------------------------------------------------
/SampleTest/Assets/Wide310x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/SampleTest/Assets/Wide310x150Logo.scale-200.png
--------------------------------------------------------------------------------
/SampleTest/MainPage.xaml:
--------------------------------------------------------------------------------
1 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 | The `LoginButton` above allows your user and application to easily connect to the Microsoft Graph. They can then also easily logout from the drop-down menu.
42 |
43 |
44 |
45 |
46 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/SampleTest/MainPage.xaml.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using Windows.UI.Xaml.Controls;
6 |
7 | namespace SampleTest
8 | {
9 | public sealed partial class MainPage : Page
10 | {
11 | public MainPage()
12 | {
13 | InitializeComponent();
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/SampleTest/Package.appxmanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
13 |
14 |
15 |
16 |
17 | SampleTest
18 | Microsoft
19 | Assets\StoreLogo.png
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
34 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/SampleTest/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System.Reflection;
6 | using System.Runtime.CompilerServices;
7 | using System.Runtime.InteropServices;
8 |
9 | // General Information about an assembly is controlled through the following
10 | // set of attributes. Change these attribute values to modify the information
11 | // associated with an assembly.
12 | [assembly: AssemblyTitle("SampleTest")]
13 | [assembly: AssemblyDescription("")]
14 | [assembly: AssemblyConfiguration("")]
15 | [assembly: AssemblyCompany("")]
16 | [assembly: AssemblyProduct("SampleTest")]
17 | [assembly: AssemblyCopyright("Copyright © 2019")]
18 | [assembly: AssemblyTrademark("")]
19 | [assembly: AssemblyCulture("")]
20 |
21 | // Version information for an assembly consists of the following four values:
22 | //
23 | // Major Version
24 | // Minor Version
25 | // Build Number
26 | // Revision
27 | //
28 | // You can specify all the values or you can default the Build and Revision Numbers
29 | // by using the '*' as shown below:
30 | // [assembly: AssemblyVersion("1.0.*")]
31 | [assembly: ComVisible(false)]
--------------------------------------------------------------------------------
/SampleTest/Properties/Default.rd.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/SampleTest/Samples/GraphPresenter/CalendarViewSample.xaml.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System;
6 | using CommunityToolkit.Authentication;
7 | using CommunityToolkit.Graph.Extensions;
8 | using Microsoft.Graph;
9 | using Microsoft.Graph.Extensions;
10 | using Windows.UI.Xaml.Controls;
11 |
12 | namespace SampleTest.Samples.GraphPresenter
13 | {
14 | public sealed partial class CalendarViewSample : Page
15 | {
16 | // Workaround for https://github.com/microsoft/microsoft-ui-xaml/issues/2407
17 | public DateTime Today => DateTimeOffset.Now.Date.ToUniversalTime();
18 |
19 | // Workaround for https://github.com/microsoft/microsoft-ui-xaml/issues/2407
20 | public DateTime ThreeDaysFromNow => Today.AddDays(3);
21 |
22 | public IBaseRequestBuilder CalendarViewRequestBuilder { get; set; }
23 |
24 | public CalendarViewSample()
25 | {
26 | this.InitializeComponent();
27 |
28 | ProviderManager.Instance.ProviderUpdated += OnProviderUpdated;
29 | ProviderManager.Instance.ProviderStateChanged += OnProviderStateChanged;
30 | }
31 |
32 | private void OnProviderUpdated(object sender, IProvider provider)
33 | {
34 | if (provider == null)
35 | {
36 | ClearRequestBuilders();
37 | }
38 | }
39 |
40 | private void OnProviderStateChanged(object sender, ProviderStateChangedEventArgs e)
41 | {
42 | if (e.NewState == ProviderState.SignedIn)
43 | {
44 | var graphClient = ProviderManager.Instance.GlobalProvider.GetClient();
45 |
46 | CalendarViewRequestBuilder = graphClient.Me.CalendarView;
47 | }
48 | else
49 | {
50 | ClearRequestBuilders();
51 | }
52 | }
53 |
54 | private void ClearRequestBuilders()
55 | {
56 | CalendarViewRequestBuilder = null;
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/SampleTest/Samples/GraphPresenter/MailMessagesSample.xaml:
--------------------------------------------------------------------------------
1 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | The following example shows the `Me.Messages` API for getting a user's inbox mail messages.
21 |
22 |
23 | My Messages:
24 |
25 |
26 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
42 |
46 |
49 |
50 |
51 |
52 |
53 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/SampleTest/Samples/GraphPresenter/MailMessagesSample.xaml.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System.Text.RegularExpressions;
6 | using CommunityToolkit.Authentication;
7 | using CommunityToolkit.Graph.Extensions;
8 | using Microsoft.Graph;
9 | using Windows.UI.Xaml.Controls;
10 |
11 | namespace SampleTest.Samples.GraphPresenter
12 | {
13 | public sealed partial class MailMessagesSample : Page
14 | {
15 | public IBaseRequestBuilder MessagesRequestBuilder { get; set; }
16 |
17 | public MailMessagesSample()
18 | {
19 | this.InitializeComponent();
20 | ProviderManager.Instance.ProviderUpdated += OnProviderUpdated;
21 | ProviderManager.Instance.ProviderStateChanged += OnProviderStateChanged;
22 | }
23 |
24 | private void OnProviderUpdated(object sender, IProvider provider)
25 | {
26 | if (provider == null)
27 | {
28 | ClearRequestBuilders();
29 | }
30 | }
31 |
32 | private void OnProviderStateChanged(object sender, ProviderStateChangedEventArgs e)
33 | {
34 | if (e.NewState == ProviderState.SignedIn)
35 | {
36 | var graphClient = ProviderManager.Instance.GlobalProvider.GetClient();
37 |
38 | MessagesRequestBuilder = graphClient.Me.Messages;
39 | }
40 | else
41 | {
42 | ClearRequestBuilders();
43 | }
44 | }
45 |
46 | private void ClearRequestBuilders()
47 | {
48 | MessagesRequestBuilder = null;
49 | }
50 |
51 | public static string RemoveWhitespace(string value)
52 | {
53 | // Workaround for https://github.com/microsoft/microsoft-ui-xaml/issues/2654
54 | return Regex.Replace(value, @"\t|\r|\n", " ");
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/SampleTest/Samples/GraphPresenter/OneDriveSample.xaml:
--------------------------------------------------------------------------------
1 |
14 |
15 |
16 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
43 |
46 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/SampleTest/Samples/GraphPresenter/OneDriveSample.xaml.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System;
6 | using System.Threading.Tasks;
7 | using CommunityToolkit.Authentication;
8 | using CommunityToolkit.Graph.Extensions;
9 | using Microsoft.Graph;
10 | using Microsoft.Toolkit;
11 | using CommunityToolkit.Mvvm.ComponentModel;
12 | using Windows.UI.Xaml.Controls;
13 | using Windows.UI.Xaml.Data;
14 |
15 | namespace SampleTest.Samples.GraphPresenter
16 | {
17 | public sealed partial class OneDriveSample : Page
18 | {
19 | public IBaseRequestBuilder RecentDriveItemsRequestBuilder { get; set; }
20 |
21 | public OneDriveSample()
22 | {
23 | InitializeComponent();
24 |
25 | ProviderManager.Instance.ProviderStateChanged += (s, e) => UpdateRequestBuilder();
26 | UpdateRequestBuilder();
27 | }
28 |
29 | private void UpdateRequestBuilder()
30 | {
31 | var provider = ProviderManager.Instance.GlobalProvider;
32 | switch (provider?.State)
33 | {
34 | case ProviderState.SignedIn:
35 | RecentDriveItemsRequestBuilder = provider.GetClient().Me.Drive.Recent();
36 | break;
37 |
38 | default:
39 | RecentDriveItemsRequestBuilder = null;
40 | break;
41 | }
42 | }
43 |
44 | private static readonly string[] Suffixes = { "B", "KB", "MB", "GB", "TB" };
45 |
46 | public static string FormatFileSize(Int64? size)
47 | {
48 | float number = size ?? throw new ArgumentNullException(nameof(size));
49 |
50 | var suffixIndex = 0;
51 | string Output() => $"{Math.Round(number)}{Suffixes[suffixIndex]}";
52 |
53 | do
54 | {
55 | if (number < 1024f)
56 | {
57 | return Output();
58 | }
59 |
60 | number = number / 1024f;
61 | }
62 | while (++suffixIndex < Suffixes.Length - 1);
63 |
64 | return Output();
65 | }
66 |
67 | public static AsyncResult GetThumbnail(RemoteItem ri)
68 | {
69 | // drives/${file.remoteItem.parentReference.driveId}/items/${file.remoteItem.id}/thumbnails/0/medium
70 | var provider = ProviderManager.Instance.GlobalProvider;
71 | if (provider?.State == ProviderState.SignedIn)
72 | {
73 | var graph = provider.GetClient();
74 | return new AsyncResult(graph.Drives[ri.ParentReference.DriveId].Items[ri.Id].Thumbnails["0"].Request().GetAsync());
75 | }
76 |
77 | return null;
78 | }
79 |
80 | public sealed class AsyncResult : ObservableObject
81 | {
82 | private TaskNotifier taskNotifier;
83 |
84 | public Task Task
85 | {
86 | get => taskNotifier;
87 | private set
88 | {
89 | SetPropertyAndNotifyOnCompletion(ref taskNotifier, value, nameof(ResultOrDefault));
90 | }
91 | }
92 |
93 | public AsyncResult(Task task)
94 | {
95 | Task = task;
96 | }
97 |
98 | public TResult ResultOrDefault => this.Task.GetResultOrDefault();
99 | }
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/SampleTest/Samples/GraphPresenter/PlannerTasksSample.xaml.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using CommunityToolkit.Authentication;
6 | using CommunityToolkit.Graph.Extensions;
7 | using Microsoft.Graph;
8 | using Windows.UI.Xaml.Controls;
9 |
10 | namespace SampleTest.Samples.GraphPresenter
11 | {
12 | public sealed partial class PlannerTasksSample : Page
13 | {
14 | public IBaseRequestBuilder PlannerTasksRequestBuilder;
15 |
16 | public PlannerTasksSample()
17 | {
18 | this.InitializeComponent();
19 |
20 | ProviderManager.Instance.ProviderUpdated += OnProviderUpdated;
21 | ProviderManager.Instance.ProviderStateChanged += OnProviderStateChanged;
22 | }
23 |
24 | private void OnProviderUpdated(object sender, IProvider provider)
25 | {
26 | if (provider == null)
27 | {
28 | ClearRequestBuilders();
29 | }
30 | }
31 |
32 | private void OnProviderStateChanged(object sender, ProviderStateChangedEventArgs e)
33 | {
34 | if (e.NewState == ProviderState.SignedIn)
35 | {
36 | var graphClient = ProviderManager.Instance.GlobalProvider.GetClient();
37 |
38 | PlannerTasksRequestBuilder = graphClient.Me.Planner.Tasks;
39 | }
40 | else
41 | {
42 | ClearRequestBuilders();
43 | }
44 | }
45 |
46 | private void ClearRequestBuilders()
47 | {
48 | PlannerTasksRequestBuilder = null;
49 | }
50 |
51 | public static bool IsTaskCompleted(int? percentCompleted)
52 | {
53 | return percentCompleted == 100;
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/SampleTest/Samples/GraphPresenter/TeamsChannelMessagesSample.xaml:
--------------------------------------------------------------------------------
1 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 | The following example shows the beta `Teams/id/Channels/id/messages` API for getting a list of messages (without replies) from a Channel in Teams.
22 |
23 |
24 | My Chat Messages:
25 |
26 |
27 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
46 |
50 |
51 |
52 |
53 |
54 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/SampleTest/Samples/GraphPresenter/TeamsChannelMessagesSample.xaml.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using CommunityToolkit.Authentication;
6 | using CommunityToolkit.Graph.Extensions;
7 | using Microsoft.Graph;
8 | using Windows.UI.Xaml.Controls;
9 |
10 | namespace SampleTest.Samples.GraphPresenter
11 | {
12 | public sealed partial class TeamsChannelMessagesSample : Page
13 | {
14 | public IBaseRequestBuilder TeamsChannelMessagesRequestBuilder { get; set; }
15 |
16 | public TeamsChannelMessagesSample()
17 | {
18 | this.InitializeComponent();
19 |
20 | ProviderManager.Instance.ProviderUpdated += OnProviderUpdated;
21 | ProviderManager.Instance.ProviderStateChanged += OnProviderStateChanged;
22 | }
23 |
24 | private void OnProviderUpdated(object sender, IProvider provider)
25 | {
26 | if (provider == null)
27 | {
28 | ClearRequestBuilders();
29 | }
30 | }
31 |
32 | private void OnProviderStateChanged(object sender, ProviderStateChangedEventArgs e)
33 | {
34 | if (e.NewState == ProviderState.SignedIn)
35 | {
36 | var graphClient = ProviderManager.Instance.GlobalProvider.GetClient();
37 |
38 | TeamsChannelMessagesRequestBuilder = graphClient.Teams["02bd9fd6-8f93-4758-87c3-1fb73740a315"].Channels["19:d0bba23c2fc8413991125a43a54cc30e@thread.skype"].Messages;
39 | }
40 | else
41 | {
42 | ClearRequestBuilders();
43 | }
44 | }
45 |
46 | private void ClearRequestBuilders()
47 | {
48 | TeamsChannelMessagesRequestBuilder = null;
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/SampleTest/Samples/GraphPresenterSample.xaml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | The `GraphPresenter` is a unique control in the library which makes it easier for a developer to make any graph call and configure a nice display template in XAML.
19 | This opens up a world of possibilities for many uses outside of any other control available within this library. You can see a few examples of what's possible below.
20 |
21 |
22 |
23 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/SampleTest/Samples/GraphPresenterSample.xaml.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System;
6 | using System.Text.RegularExpressions;
7 | using CommunityToolkit.Authentication;
8 | using CommunityToolkit.Graph.Extensions;
9 | using Microsoft.Graph;
10 | using Microsoft.Graph.Extensions;
11 | using Windows.UI.Xaml.Controls;
12 |
13 | namespace SampleTest.Samples
14 | {
15 | public sealed partial class GraphPresenterSample : Page
16 | {
17 | public static string ToLocalTime(DateTimeTimeZone value)
18 | {
19 | // Workaround for https://github.com/microsoft/microsoft-ui-xaml/issues/2407
20 | return value.ToDateTimeOffset().LocalDateTime.ToString("g");
21 | }
22 |
23 | public static string ToLocalTime(DateTimeOffset? value)
24 | {
25 | // Workaround for https://github.com/microsoft/microsoft-ui-xaml/issues/2654
26 | return value?.LocalDateTime.ToString("g");
27 | }
28 |
29 | public GraphPresenterSample()
30 | {
31 | InitializeComponent();
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/SampleTest/Samples/PeoplePickerSample.xaml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
20 | The `PeoplePicker` lets a logged in user easily search for familiar people they interact with or contacts. Great for emails or messages.
21 |
22 |
24 |
26 | Picked People:
27 |
28 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/SampleTest/Samples/PeoplePickerSample.xaml.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System.Collections.ObjectModel;
6 | using Microsoft.Graph;
7 | using Windows.UI.Xaml.Controls;
8 |
9 | namespace SampleTest.Samples
10 | {
11 | public sealed partial class PeoplePickerSample : Page
12 | {
13 | ObservableCollection MyPeople { get; set; } = new();
14 |
15 | public PeoplePickerSample()
16 | {
17 | InitializeComponent();
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/SampleTest/Samples/PersonViewSample.xaml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/SampleTest/Samples/PersonViewSample.xaml.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using Windows.UI.Xaml.Controls;
6 |
7 | namespace SampleTest.Samples
8 | {
9 | public sealed partial class PersonViewSample : Page
10 | {
11 | public PersonViewSample()
12 | {
13 | InitializeComponent();
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/Samples/ManualGraphRequestSample/App.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Samples/ManualGraphRequestSample/App.xaml.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using Windows.ApplicationModel.Activation;
6 | using Windows.UI.Xaml;
7 | using Windows.UI.Xaml.Controls;
8 |
9 | namespace ManualGraphRequestSample
10 | {
11 | sealed partial class App : Application
12 | {
13 |
14 | public App()
15 | {
16 | InitializeComponent();
17 | }
18 |
19 | protected override void OnLaunched(LaunchActivatedEventArgs e)
20 | {
21 | Frame rootFrame = Window.Current.Content as Frame;
22 | if (rootFrame == null)
23 | {
24 | rootFrame = new Frame();
25 | Window.Current.Content = rootFrame;
26 | }
27 |
28 | if (e.PrelaunchActivated == false)
29 | {
30 | if (rootFrame.Content == null)
31 | {
32 | rootFrame.Navigate(typeof(MainPage), e.Arguments);
33 | }
34 |
35 | Window.Current.Activate();
36 | }
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Samples/ManualGraphRequestSample/Assets/LockScreenLogo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/Samples/ManualGraphRequestSample/Assets/LockScreenLogo.scale-200.png
--------------------------------------------------------------------------------
/Samples/ManualGraphRequestSample/Assets/SplashScreen.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/Samples/ManualGraphRequestSample/Assets/SplashScreen.scale-200.png
--------------------------------------------------------------------------------
/Samples/ManualGraphRequestSample/Assets/Square150x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/Samples/ManualGraphRequestSample/Assets/Square150x150Logo.scale-200.png
--------------------------------------------------------------------------------
/Samples/ManualGraphRequestSample/Assets/Square44x44Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/Samples/ManualGraphRequestSample/Assets/Square44x44Logo.scale-200.png
--------------------------------------------------------------------------------
/Samples/ManualGraphRequestSample/Assets/Square44x44Logo.targetsize-24_altform-unplated.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/Samples/ManualGraphRequestSample/Assets/Square44x44Logo.targetsize-24_altform-unplated.png
--------------------------------------------------------------------------------
/Samples/ManualGraphRequestSample/Assets/StoreLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/Samples/ManualGraphRequestSample/Assets/StoreLogo.png
--------------------------------------------------------------------------------
/Samples/ManualGraphRequestSample/Assets/Wide310x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/Samples/ManualGraphRequestSample/Assets/Wide310x150Logo.scale-200.png
--------------------------------------------------------------------------------
/Samples/ManualGraphRequestSample/MainPage.xaml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
22 |
27 |
34 |
35 |
36 |
42 |
43 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/Samples/ManualGraphRequestSample/MainPage.xaml.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using CommunityToolkit.Authentication;
6 | using ManualGraphRequestSample.Models;
7 | using Newtonsoft.Json;
8 | using Newtonsoft.Json.Linq;
9 | using System.Collections.Generic;
10 | using System.Collections.ObjectModel;
11 | using System.Net.Http;
12 | using System.Threading.Tasks;
13 | using Windows.UI.Xaml;
14 | using Windows.UI.Xaml.Controls;
15 |
16 | namespace ManualGraphRequestSample
17 | {
18 | public sealed partial class MainPage : Page
19 | {
20 | public ObservableCollection TaskCollection = new ObservableCollection();
21 |
22 | public MainPage()
23 | {
24 | InitializeComponent();
25 |
26 | ProviderManager.Instance.ProviderStateChanged += OnProviderStateChanged;
27 | ProviderManager.Instance.GlobalProvider = new WindowsProvider(new string[] { "User.Read", "Tasks.ReadWrite" });
28 | }
29 |
30 | private async void OnProviderStateChanged(object sender, ProviderStateChangedEventArgs e)
31 | {
32 | switch (e.NewState)
33 | {
34 | case ProviderState.Loading:
35 | SignInButton.Content = "Loading...";
36 | SignInLoadingRing.IsActive = true;
37 | SignInButton.IsEnabled = false;
38 | break;
39 |
40 | case ProviderState.SignedOut:
41 | SignInButton.Content = "Sign In";
42 | SignInLoadingRing.IsActive = false;
43 | SignInButton.IsEnabled = true;
44 |
45 | TaskCollection.Clear();
46 | break;
47 |
48 | case ProviderState.SignedIn:
49 | SignInButton.Content = "Sign Out";
50 | SignInLoadingRing.IsActive = false;
51 | SignInButton.IsEnabled = true;
52 |
53 | IList tasks = await GetDefaultTaskListAsync();
54 | if (tasks != null)
55 | {
56 | foreach (var task in tasks)
57 | {
58 | TaskCollection.Add(task);
59 | }
60 | }
61 | break;
62 | }
63 | }
64 |
65 | private async void OnSignInButtonClick(object sender, RoutedEventArgs e)
66 | {
67 | IProvider provider = ProviderManager.Instance.GlobalProvider;
68 | if (provider?.State == ProviderState.SignedOut)
69 | {
70 | await ProviderManager.Instance.GlobalProvider.SignInAsync();
71 | }
72 | else if (provider?.State == ProviderState.SignedIn)
73 | {
74 | await ProviderManager.Instance.GlobalProvider.SignOutAsync();
75 | }
76 | }
77 |
78 | private async Task> GetDefaultTaskListAsync()
79 | {
80 | var httpClient = new HttpClient();
81 | var requestUri = "https://graph.microsoft.com/v1.0/me/todo/lists/tasks/tasks";
82 |
83 | var getRequest = new HttpRequestMessage(HttpMethod.Get, requestUri);
84 | await ProviderManager.Instance.GlobalProvider.AuthenticateRequestAsync(getRequest);
85 |
86 | using (httpClient)
87 | {
88 | var response = await httpClient.SendAsync(getRequest);
89 |
90 | if (response.IsSuccessStatusCode)
91 | {
92 | var jsonResponse = await response.Content.ReadAsStringAsync();
93 | var jObject = JObject.Parse(jsonResponse);
94 | if (jObject.ContainsKey("value"))
95 | {
96 | var tasks = JsonConvert.DeserializeObject>(jObject["value"].ToString());
97 | return tasks;
98 | }
99 | }
100 | }
101 |
102 | return null;
103 | }
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/Samples/ManualGraphRequestSample/Models/TodoTask.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using Newtonsoft.Json;
6 |
7 | namespace ManualGraphRequestSample.Models
8 | {
9 | ///
10 | /// The type Todo Task.
11 | /// The complete type definition can refer to here: https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/dev/src/Microsoft.Graph/Generated/model/TodoTask.cs
12 | ///
13 | [JsonObject(MemberSerialization = MemberSerialization.OptIn)]
14 | public class TodoTask
15 | {
16 | ///
17 | /// Initializes a new instance of the class.
18 | ///
19 | public TodoTask()
20 | {
21 | this.ODataType = "microsoft.graph.todoTask";
22 | }
23 |
24 | ///
25 | /// Gets or sets @odata.type.
26 | ///
27 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "@odata.type", Required = Required.Default)]
28 | public string ODataType { get; set; }
29 |
30 | ///
31 | /// Gets or sets id.
32 | ///
33 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "id", Required = Required.Default)]
34 | public string Id { get; set; }
35 |
36 | ///
37 | /// Gets or sets title.
38 | /// A brief description of the task.
39 | ///
40 | [JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "title", Required = Required.Default)]
41 | public string Title { get; set; }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/Samples/ManualGraphRequestSample/Package.appxmanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
13 |
14 |
15 |
16 |
17 | ManualGraphRequestSample
18 | Microsoft
19 | Assets\StoreLogo.png
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
34 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/Samples/ManualGraphRequestSample/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System.Reflection;
6 | using System.Runtime.InteropServices;
7 |
8 | // General Information about an assembly is controlled through the following
9 | // set of attributes. Change these attribute values to modify the information
10 | // associated with an assembly.
11 | [assembly: AssemblyTitle("ManualGraphRequestSample")]
12 | [assembly: AssemblyDescription("")]
13 | [assembly: AssemblyConfiguration("")]
14 | [assembly: AssemblyCompany("")]
15 | [assembly: AssemblyProduct("ManualGraphRequestSample")]
16 | [assembly: AssemblyCopyright("Copyright © 2021")]
17 | [assembly: AssemblyTrademark("")]
18 | [assembly: AssemblyCulture("")]
19 |
20 | // Version information for an assembly consists of the following four values:
21 | //
22 | // Major Version
23 | // Minor Version
24 | // Build Number
25 | // Revision
26 | //
27 | // You can specify all the values or you can default the Build and Revision Numbers
28 | // by using the '*' as shown below:
29 | // [assembly: AssemblyVersion("1.0.*")]
30 | [assembly: ComVisible(false)]
--------------------------------------------------------------------------------
/Samples/ManualGraphRequestSample/Properties/Default.rd.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/Samples/UwpMsalProviderSample/App.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Samples/UwpMsalProviderSample/App.xaml.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using CommunityToolkit.Authentication;
6 | using Windows.ApplicationModel.Activation;
7 | using Windows.System;
8 | using Windows.UI.Xaml;
9 | using Windows.UI.Xaml.Controls;
10 |
11 | namespace UwpMsalProviderSample
12 | {
13 | sealed partial class App : Application
14 | {
15 | public App()
16 | {
17 | this.InitializeComponent();
18 | }
19 |
20 | ///
21 | /// Sets the global IProvider instance for authentication using the official MSAL library.
22 | ///
23 | void ConfigureGlobalProvider()
24 | {
25 | if (ProviderManager.Instance.GlobalProvider == null)
26 | {
27 | string clientId = "YOUR-CLIENT-ID-HERE";
28 | string[] scopes = new string[] { "User.Read" };
29 | ProviderManager.Instance.GlobalProvider = new MsalProvider(clientId, scopes);
30 | }
31 | }
32 |
33 | protected override void OnLaunched(LaunchActivatedEventArgs e)
34 | {
35 | Frame rootFrame = Window.Current.Content as Frame;
36 | if (rootFrame == null)
37 | {
38 | rootFrame = new Frame();
39 | Window.Current.Content = rootFrame;
40 | }
41 |
42 | if (e.PrelaunchActivated == false)
43 | {
44 | if (rootFrame.Content == null)
45 | {
46 | rootFrame.Navigate(typeof(MainPage), e.Arguments);
47 | }
48 |
49 | Window.Current.Activate();
50 |
51 | ConfigureGlobalProvider();
52 | }
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/Samples/UwpMsalProviderSample/Assets/LockScreenLogo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/Samples/UwpMsalProviderSample/Assets/LockScreenLogo.scale-200.png
--------------------------------------------------------------------------------
/Samples/UwpMsalProviderSample/Assets/SplashScreen.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/Samples/UwpMsalProviderSample/Assets/SplashScreen.scale-200.png
--------------------------------------------------------------------------------
/Samples/UwpMsalProviderSample/Assets/Square150x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/Samples/UwpMsalProviderSample/Assets/Square150x150Logo.scale-200.png
--------------------------------------------------------------------------------
/Samples/UwpMsalProviderSample/Assets/Square44x44Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/Samples/UwpMsalProviderSample/Assets/Square44x44Logo.scale-200.png
--------------------------------------------------------------------------------
/Samples/UwpMsalProviderSample/Assets/Square44x44Logo.targetsize-24_altform-unplated.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/Samples/UwpMsalProviderSample/Assets/Square44x44Logo.targetsize-24_altform-unplated.png
--------------------------------------------------------------------------------
/Samples/UwpMsalProviderSample/Assets/StoreLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/Samples/UwpMsalProviderSample/Assets/StoreLogo.png
--------------------------------------------------------------------------------
/Samples/UwpMsalProviderSample/Assets/Wide310x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/Samples/UwpMsalProviderSample/Assets/Wide310x150Logo.scale-200.png
--------------------------------------------------------------------------------
/Samples/UwpMsalProviderSample/MainPage.xaml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/Samples/UwpMsalProviderSample/MainPage.xaml.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using CommunityToolkit.Authentication;
6 | using CommunityToolkit.Graph.Extensions;
7 | using Windows.UI.Xaml.Controls;
8 |
9 | namespace UwpMsalProviderSample
10 | {
11 | public sealed partial class MainPage : Page
12 | {
13 | public MainPage()
14 | {
15 | this.InitializeComponent();
16 |
17 | ProviderManager.Instance.ProviderStateChanged += OnProviderStateChanged;
18 | }
19 |
20 | private async void OnProviderStateChanged(object sender, ProviderStateChangedEventArgs e)
21 | {
22 | if (e.NewState == ProviderState.SignedIn)
23 | {
24 | SignedInUserTextBlock.Text = "Signed in as...";
25 |
26 | var graphClient = ProviderManager.Instance.GlobalProvider.GetClient();
27 | var me = await graphClient.Me.Request().GetAsync();
28 |
29 | SignedInUserTextBlock.Text = "Signed in as: " + me.DisplayName;
30 | }
31 | else
32 | {
33 | SignedInUserTextBlock.Text = "Please sign in.";
34 | }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Samples/UwpMsalProviderSample/Package.appxmanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
13 |
14 |
15 |
16 |
17 | UwpMsalProviderSample
18 | Microsoft
19 | Assets\StoreLogo.png
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
34 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/Samples/UwpMsalProviderSample/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System.Reflection;
6 | using System.Runtime.InteropServices;
7 |
8 | // General Information about an assembly is controlled through the following
9 | // set of attributes. Change these attribute values to modify the information
10 | // associated with an assembly.
11 | [assembly: AssemblyTitle("UwpMsalProviderSample")]
12 | [assembly: AssemblyDescription("")]
13 | [assembly: AssemblyConfiguration("")]
14 | [assembly: AssemblyCompany("")]
15 | [assembly: AssemblyProduct("UwpMsalProviderSample")]
16 | [assembly: AssemblyCopyright("Copyright © 2021")]
17 | [assembly: AssemblyTrademark("")]
18 | [assembly: AssemblyCulture("")]
19 |
20 | // Version information for an assembly consists of the following four values:
21 | //
22 | // Major Version
23 | // Minor Version
24 | // Build Number
25 | // Revision
26 | //
27 | // You can specify all the values or you can default the Build and Revision Numbers
28 | // by using the '*' as shown below:
29 | // [assembly: AssemblyVersion("1.0.*")]
30 | [assembly: ComVisible(false)]
--------------------------------------------------------------------------------
/Samples/UwpMsalProviderSample/Properties/Default.rd.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/Samples/UwpMsalProviderSample/README.md:
--------------------------------------------------------------------------------
1 | # MsalProvider Authentication Sample for UWP
2 |
3 | This sample demonstrates how to configure the MsalProvider to authenticate consumer MSA and organizational AAD accounts in your apps.
4 |
5 | ```
6 | string clientId = "YOUR-CLIENT-ID-HERE";
7 | string[] scopes = new string[] { "User.Read" };
8 | ProviderManager.Instance.GlobalProvider = new MsalProvider(clientId, scopes);
9 | ```
10 |
11 | It uses an IProvider implementation called MsalProvider, which leverages the official Microsoft Authentication Library (MSAL)
12 | to enable authentication for MSA and AAD accounts.
--------------------------------------------------------------------------------
/Samples/UwpWindowsProviderSample/AccountManagerButton.xaml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Samples/UwpWindowsProviderSample/AccountManagerButton.xaml.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using CommunityToolkit.Authentication;
6 | using Windows.UI.Xaml;
7 | using Windows.UI.Xaml.Controls;
8 |
9 | namespace UwpWindowsProviderSample
10 | {
11 | ///
12 | /// A simple button for triggering the globally configured WindowsProvider to manage account.
13 | ///
14 | public sealed partial class AccountManagerButton : UserControl
15 | {
16 | public AccountManagerButton()
17 | {
18 | this.InitializeComponent();
19 | }
20 |
21 | private async void ManagerButton_Click(object sender, RoutedEventArgs e)
22 | {
23 | if(ProviderManager.Instance.GlobalProvider is WindowsProvider provider)
24 | {
25 | await provider.ShowAccountManagementPaneAsync();
26 | }
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Samples/UwpWindowsProviderSample/App.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Samples/UwpWindowsProviderSample/App.xaml.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using CommunityToolkit.Authentication;
6 | using System.Diagnostics;
7 | using Windows.ApplicationModel.Activation;
8 | using Windows.System;
9 | using Windows.UI.ApplicationSettings;
10 | using Windows.UI.Xaml;
11 | using Windows.UI.Xaml.Controls;
12 |
13 | namespace UwpWindowsProviderSample
14 | {
15 | sealed partial class App : Application
16 | {
17 | public App()
18 | {
19 | this.InitializeComponent();
20 | }
21 |
22 | ///
23 | /// Sets the global IProvider instance for authentication using native Windows Account Manager APIs.
24 | ///
25 | /// Don't forget to associate your app with the store as well. The WindowsProvider leverages the
26 | /// default app registration that comes with store assocation, no clientId required!
27 | ///
28 | /// For now only consumer MSA accounts supported, however organizational AAD account support is planned and coming soon.
29 | ///
30 | void ConfigureGlobalProvider()
31 | {
32 | if (ProviderManager.Instance.GlobalProvider == null)
33 | {
34 | string[] scopes = new string[] { "User.Read" };
35 | var paneConfig = GetAccountsSettingsPaneConfig();
36 | ProviderManager.Instance.GlobalProvider = new WindowsProvider(scopes, accountsSettingsPaneConfig: paneConfig);
37 | }
38 | }
39 |
40 | AccountsSettingsPaneConfig GetAccountsSettingsPaneConfig()
41 | {
42 | void OnAccountCommandInvoked(WebAccountCommand command, WebAccountInvokedArgs args)
43 | {
44 | Debug.WriteLine($"Action: {args.Action}");
45 | }
46 |
47 | var accountCommandParameter = new WebAccountCommandParameter(
48 | OnAccountCommandInvoked,
49 | SupportedWebAccountActions.Manage | SupportedWebAccountActions.Remove);
50 |
51 | var addAccountHeaderText = "Login account";
52 | var manageAccountHeaderText = "Account management";
53 |
54 | return new AccountsSettingsPaneConfig(addAccountHeaderText, manageAccountHeaderText, accountCommandParameter: accountCommandParameter);
55 | }
56 |
57 | protected override void OnLaunched(LaunchActivatedEventArgs e)
58 | {
59 | Frame rootFrame = Window.Current.Content as Frame;
60 | if (rootFrame == null)
61 | {
62 | rootFrame = new Frame();
63 | Window.Current.Content = rootFrame;
64 | }
65 |
66 | if (e.PrelaunchActivated == false)
67 | {
68 | if (rootFrame.Content == null)
69 | {
70 | rootFrame.Navigate(typeof(MainPage), e.Arguments);
71 | }
72 |
73 | Window.Current.Activate();
74 |
75 | ConfigureGlobalProvider();
76 | }
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/Samples/UwpWindowsProviderSample/Assets/LockScreenLogo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/Samples/UwpWindowsProviderSample/Assets/LockScreenLogo.scale-200.png
--------------------------------------------------------------------------------
/Samples/UwpWindowsProviderSample/Assets/SplashScreen.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/Samples/UwpWindowsProviderSample/Assets/SplashScreen.scale-200.png
--------------------------------------------------------------------------------
/Samples/UwpWindowsProviderSample/Assets/Square150x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/Samples/UwpWindowsProviderSample/Assets/Square150x150Logo.scale-200.png
--------------------------------------------------------------------------------
/Samples/UwpWindowsProviderSample/Assets/Square44x44Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/Samples/UwpWindowsProviderSample/Assets/Square44x44Logo.scale-200.png
--------------------------------------------------------------------------------
/Samples/UwpWindowsProviderSample/Assets/Square44x44Logo.targetsize-24_altform-unplated.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/Samples/UwpWindowsProviderSample/Assets/Square44x44Logo.targetsize-24_altform-unplated.png
--------------------------------------------------------------------------------
/Samples/UwpWindowsProviderSample/Assets/StoreLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/Samples/UwpWindowsProviderSample/Assets/StoreLogo.png
--------------------------------------------------------------------------------
/Samples/UwpWindowsProviderSample/Assets/Wide310x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/Samples/UwpWindowsProviderSample/Assets/Wide310x150Logo.scale-200.png
--------------------------------------------------------------------------------
/Samples/UwpWindowsProviderSample/MainPage.xaml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
13 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/Samples/UwpWindowsProviderSample/MainPage.xaml.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using CommunityToolkit.Authentication;
6 | using CommunityToolkit.Graph.Extensions;
7 | using Windows.UI.Xaml.Controls;
8 |
9 | namespace UwpWindowsProviderSample
10 | {
11 | public sealed partial class MainPage : Page
12 | {
13 | public MainPage()
14 | {
15 | this.InitializeComponent();
16 |
17 | ProviderManager.Instance.ProviderStateChanged += OnProviderStateChanged;
18 | }
19 |
20 | private async void OnProviderStateChanged(object sender, ProviderStateChangedEventArgs e)
21 | {
22 | if (e.NewState == ProviderState.SignedIn)
23 | {
24 | ManagerButton.IsEnabled = true;
25 | SignedInUserTextBlock.Text = "Signed in as...";
26 |
27 | var graphClient = ProviderManager.Instance.GlobalProvider.GetClient();
28 | var me = await graphClient.Me.Request().GetAsync();
29 |
30 | SignedInUserTextBlock.Text = "Signed in as: " + me.DisplayName;
31 | }
32 | else
33 | {
34 | SignedInUserTextBlock.Text = "Please sign in.";
35 | ManagerButton.IsEnabled = false;
36 | }
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Samples/UwpWindowsProviderSample/Package.appxmanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
13 |
14 |
15 |
16 |
17 | UwpWindowsProviderSample
18 | Microsoft
19 | Assets\StoreLogo.png
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
34 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/Samples/UwpWindowsProviderSample/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System.Reflection;
6 | using System.Runtime.InteropServices;
7 |
8 | // General Information about an assembly is controlled through the following
9 | // set of attributes. Change these attribute values to modify the information
10 | // associated with an assembly.
11 | [assembly: AssemblyTitle("UwpWindowsProviderSample")]
12 | [assembly: AssemblyDescription("")]
13 | [assembly: AssemblyConfiguration("")]
14 | [assembly: AssemblyCompany("")]
15 | [assembly: AssemblyProduct("UwpWindowsProviderSample")]
16 | [assembly: AssemblyCopyright("Copyright © 2021")]
17 | [assembly: AssemblyTrademark("")]
18 | [assembly: AssemblyCulture("")]
19 |
20 | // Version information for an assembly consists of the following four values:
21 | //
22 | // Major Version
23 | // Minor Version
24 | // Build Number
25 | // Revision
26 | //
27 | // You can specify all the values or you can default the Build and Revision Numbers
28 | // by using the '*' as shown below:
29 | // [assembly: AssemblyVersion("1.0.*")]
30 | [assembly: ComVisible(false)]
--------------------------------------------------------------------------------
/Samples/UwpWindowsProviderSample/Properties/Default.rd.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/Samples/UwpWindowsProviderSample/README.md:
--------------------------------------------------------------------------------
1 | # WindowsProvider Authentication Sample for UWP
2 |
3 | This sample demonstrates how to configure the WindowsProvider to authenticate consumer MSAs in your apps.
4 |
5 | ```
6 | string[] scopes = new string[] { "User.Read" };
7 | ProviderManager.Instance.GlobalProvider = new WindowsProvider(scopes);
8 | ```
9 |
10 | It uses a simple IProvider implementation called WindowsProvider, which leverages native Windows Account Manager
11 | APIs to enable authentication with any locally configured accounts on Windows.
12 |
13 | Perhaps the best part is that it doesn't require any AAD configuration for authentication of consumer MSA accounts!
14 |
15 | By first registering your app with the Microsoft Store, the WindowsProvider will use the app registration built right into the Store association.
16 |
17 | > You will need a Microsoft Partner Center account for this, so if you don't have one yet head over to get signed up: https://partner.microsoft.com/dashboard
--------------------------------------------------------------------------------
/Samples/WpfNetCoreMsalProviderSample/App.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Samples/WpfNetCoreMsalProviderSample/App.xaml.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 | using CommunityToolkit.Authentication;
9 | using CommunityToolkit.Authentication.Extensions;
10 | using Microsoft.Identity.Client.Extensions.Msal;
11 |
12 | namespace WpfNetCoreMsalProviderSample
13 | {
14 | public partial class App : Application
15 | {
16 | static readonly string ClientId = "YOUR-CLIENT-ID-HERE";
17 | static readonly string[] Scopes = new string[] { "User.Read" };
18 |
19 | protected override void OnActivated(EventArgs e)
20 | {
21 | InitializeGlobalProviderAsync();
22 | base.OnActivated(e);
23 | }
24 |
25 | private async Task InitializeGlobalProviderAsync()
26 | {
27 | if (ProviderManager.Instance.GlobalProvider == null)
28 | {
29 | var provider = new MsalProvider(ClientId, Scopes, null, false, true);
30 |
31 | // Configure the token cache storage for non-UWP applications.
32 | var storageProperties = new StorageCreationPropertiesBuilder(CacheConfig.CacheFileName, CacheConfig.CacheDir)
33 | .WithLinuxKeyring(
34 | CacheConfig.LinuxKeyRingSchema,
35 | CacheConfig.LinuxKeyRingCollection,
36 | CacheConfig.LinuxKeyRingLabel,
37 | CacheConfig.LinuxKeyRingAttr1,
38 | CacheConfig.LinuxKeyRingAttr2)
39 | .WithMacKeyChain(
40 | CacheConfig.KeyChainServiceName,
41 | CacheConfig.KeyChainAccountName)
42 | .Build();
43 | await provider.InitTokenCacheAsync(storageProperties);
44 |
45 | ProviderManager.Instance.GlobalProvider = provider;
46 |
47 | await provider.TrySilentSignInAsync();
48 | }
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Samples/WpfNetCoreMsalProviderSample/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System.Windows;
6 |
7 | [assembly: ThemeInfo(
8 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
9 | //(used if a resource is not found in the page,
10 | // or application resource dictionaries)
11 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
12 | //(used if a resource is not found in the page,
13 | // app, or any theme specific resource dictionaries)
14 | )]
15 |
--------------------------------------------------------------------------------
/Samples/WpfNetCoreMsalProviderSample/CacheConfig.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System.Collections.Generic;
6 | using Microsoft.Identity.Client.Extensions.Msal;
7 |
8 | namespace WpfNetCoreMsalProviderSample
9 | {
10 | ///
11 | /// https://github.com/AzureAD/microsoft-authentication-extensions-for-dotnet/wiki/Cross-platform-Token-Cache
12 | ///
13 | class CacheConfig
14 | {
15 | public const string CacheFileName = "msal_cache.dat";
16 | public const string CacheDir = "MSAL_CACHE";
17 |
18 | public const string KeyChainServiceName = "msal_service";
19 | public const string KeyChainAccountName = "msal_account";
20 |
21 | public const string LinuxKeyRingSchema = "com.contoso.devtools.tokencache";
22 | public const string LinuxKeyRingCollection = MsalCacheHelper.LinuxKeyRingDefaultCollection;
23 | public const string LinuxKeyRingLabel = "MSAL token cache for all Contoso dev tool apps.";
24 | public static readonly KeyValuePair LinuxKeyRingAttr1 = new KeyValuePair("Version", "1");
25 | public static readonly KeyValuePair LinuxKeyRingAttr2 = new KeyValuePair("ProductGroup", "MyApps");
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Samples/WpfNetCoreMsalProviderSample/LoginButton.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Samples/WpfNetCoreMsalProviderSample/LoginButton.xaml.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using CommunityToolkit.Authentication;
9 |
10 | namespace WpfNetCoreMsalProviderSample
11 | {
12 | ///
13 | /// A simple button for triggering the globally configured IProvider to sign in and out.
14 | ///
15 | public partial class LoginButton : UserControl
16 | {
17 | public LoginButton()
18 | {
19 | InitializeComponent();
20 |
21 | ProviderManager.Instance.ProviderStateChanged += (s, e) => UpdateState();
22 | UpdateState();
23 | }
24 |
25 | private void UpdateState()
26 | {
27 | var provider = ProviderManager.Instance.GlobalProvider;
28 | if (provider == null || provider.State == ProviderState.Loading)
29 | {
30 | MyButton.Content = "Sign in";
31 | IsEnabled = false;
32 | return;
33 | }
34 |
35 | switch (provider.State)
36 | {
37 | case ProviderState.SignedIn:
38 | MyButton.Content = "Sign out";
39 | break;
40 |
41 | case ProviderState.SignedOut:
42 | MyButton.Content = "Sign in";
43 | break;
44 | }
45 |
46 | IsEnabled = true;
47 | }
48 |
49 | private void MyButton_Click(object sender, RoutedEventArgs e)
50 | {
51 | Application.Current.Dispatcher.Invoke(new Action(() =>
52 | {
53 | var provider = ProviderManager.Instance.GlobalProvider;
54 | if (provider != null)
55 | {
56 | switch (provider.State)
57 | {
58 | case ProviderState.SignedOut:
59 | provider.SignInAsync();
60 | break;
61 |
62 | case ProviderState.SignedIn:
63 | provider.SignOutAsync();
64 | break;
65 | }
66 | }
67 | }));
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/Samples/WpfNetCoreMsalProviderSample/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/Samples/WpfNetCoreMsalProviderSample/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System.Windows;
6 | using CommunityToolkit.Authentication;
7 | using CommunityToolkit.Graph.Extensions;
8 |
9 | namespace WpfNetCoreMsalProviderSample
10 | {
11 | public partial class MainWindow : Window
12 | {
13 | public MainWindow()
14 | {
15 | InitializeComponent();
16 |
17 | ProviderManager.Instance.ProviderStateChanged += OnProviderStateChanged;
18 | }
19 |
20 | private async void OnProviderStateChanged(object sender, ProviderStateChangedEventArgs e)
21 | {
22 | if (e.NewState == ProviderState.SignedIn)
23 | {
24 | SignedInUserTextBlock.Text = "Signed in as...";
25 |
26 | var graphClient = ProviderManager.Instance.GlobalProvider.GetClient();
27 | var me = await graphClient.Me.Request().GetAsync();
28 |
29 | SignedInUserTextBlock.Text = "Signed in as: " + me.DisplayName;
30 | }
31 | else
32 | {
33 | SignedInUserTextBlock.Text = "Please sign in.";
34 | }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Samples/WpfNetCoreMsalProviderSample/README.md:
--------------------------------------------------------------------------------
1 | # MsalProvider Authentication Sample for .NET Core 3.1 WPF apps
2 |
3 | This sample demonstrates how to configure the MsalProvider to authenticate consumer MSA and organizational AAD accounts in your apps.
4 |
5 | ```
6 | string ClientId = "YOUR-CLIENT-ID-HERE";
7 | string[] Scopes = new string[] { "User.Read" };
8 |
9 | var provider = new MsalProvider(ClientId, Scopes, null, false, true);
10 |
11 | // Configure the token cache storage for non-UWP applications.
12 | var storageProperties = new StorageCreationPropertiesBuilder(CacheConfig.CacheFileName, CacheConfig.CacheDir)
13 | .WithLinuxKeyring(
14 | CacheConfig.LinuxKeyRingSchema,
15 | CacheConfig.LinuxKeyRingCollection,
16 | CacheConfig.LinuxKeyRingLabel,
17 | CacheConfig.LinuxKeyRingAttr1,
18 | CacheConfig.LinuxKeyRingAttr2)
19 | .WithMacKeyChain(
20 | CacheConfig.KeyChainServiceName,
21 | CacheConfig.KeyChainAccountName)
22 | .Build();
23 | await provider.InitTokenCacheAsync(storageProperties);
24 |
25 | ProviderManager.Instance.GlobalProvider = provider;
26 |
27 | await provider.TrySilentSignInAsync();
28 | ```
29 |
30 | It uses an IProvider implementation called MsalProvider, which leverages the official Microsoft Authentication Library (MSAL)
31 | to enable authentication for MSA and AAD accounts.
32 |
--------------------------------------------------------------------------------
/Samples/WpfNetCoreMsalProviderSample/WpfNetCoreMsalProviderSample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | WinExe
5 | netcoreapp3.1
6 | true
7 | false
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/Samples/WpfNetWindowsMsalProviderSample/App.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Samples/WpfNetWindowsMsalProviderSample/App.xaml.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 | using CommunityToolkit.Authentication;
9 | using CommunityToolkit.Authentication.Extensions;
10 | using Microsoft.Identity.Client.Extensions.Msal;
11 |
12 | namespace WpfNetWindowsMsalProviderSample
13 | {
14 | public partial class App : Application
15 | {
16 | static readonly string ClientId = "YOUR-CLIENT-ID-HERE";
17 | static readonly string[] Scopes = new string[] { "User.Read" };
18 |
19 | protected override void OnActivated(EventArgs e)
20 | {
21 | InitializeGlobalProviderAsync();
22 | base.OnActivated(e);
23 | }
24 |
25 | private async Task InitializeGlobalProviderAsync()
26 | {
27 | if (ProviderManager.Instance.GlobalProvider == null)
28 | {
29 | var provider = new MsalProvider(ClientId, Scopes, null, false, true);
30 |
31 | // Configure the token cache storage for non-UWP applications.
32 | var storageProperties = new StorageCreationPropertiesBuilder(CacheConfig.CacheFileName, CacheConfig.CacheDir)
33 | .WithLinuxKeyring(
34 | CacheConfig.LinuxKeyRingSchema,
35 | CacheConfig.LinuxKeyRingCollection,
36 | CacheConfig.LinuxKeyRingLabel,
37 | CacheConfig.LinuxKeyRingAttr1,
38 | CacheConfig.LinuxKeyRingAttr2)
39 | .WithMacKeyChain(
40 | CacheConfig.KeyChainServiceName,
41 | CacheConfig.KeyChainAccountName)
42 | .Build();
43 | await provider.InitTokenCacheAsync(storageProperties);
44 |
45 | ProviderManager.Instance.GlobalProvider = provider;
46 |
47 | await provider.TrySilentSignInAsync();
48 | }
49 | }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Samples/WpfNetWindowsMsalProviderSample/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System.Windows;
6 |
7 | [assembly: ThemeInfo(
8 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
9 | //(used if a resource is not found in the page,
10 | // or application resource dictionaries)
11 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
12 | //(used if a resource is not found in the page,
13 | // app, or any theme specific resource dictionaries)
14 | )]
15 |
--------------------------------------------------------------------------------
/Samples/WpfNetWindowsMsalProviderSample/CacheConfig.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System.Collections.Generic;
6 | using Microsoft.Identity.Client.Extensions.Msal;
7 |
8 | namespace WpfNetWindowsMsalProviderSample
9 | {
10 | ///
11 | /// https://github.com/AzureAD/microsoft-authentication-extensions-for-dotnet/wiki/Cross-platform-Token-Cache
12 | ///
13 | class CacheConfig
14 | {
15 | public const string CacheFileName = "msal_cache.dat";
16 | public const string CacheDir = "MSAL_CACHE";
17 |
18 | public const string KeyChainServiceName = "msal_service";
19 | public const string KeyChainAccountName = "msal_account";
20 |
21 | public const string LinuxKeyRingSchema = "com.contoso.devtools.tokencache";
22 | public const string LinuxKeyRingCollection = MsalCacheHelper.LinuxKeyRingDefaultCollection;
23 | public const string LinuxKeyRingLabel = "MSAL token cache for all Contoso dev tool apps.";
24 | public static readonly KeyValuePair LinuxKeyRingAttr1 = new KeyValuePair("Version", "1");
25 | public static readonly KeyValuePair LinuxKeyRingAttr2 = new KeyValuePair("ProductGroup", "MyApps");
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/Samples/WpfNetWindowsMsalProviderSample/LoginButton.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Samples/WpfNetWindowsMsalProviderSample/LoginButton.xaml.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using CommunityToolkit.Authentication;
6 | using System;
7 | using System.Windows;
8 | using System.Windows.Controls;
9 |
10 | namespace WpfNetWindowsMsalProviderSample
11 | {
12 | ///
13 | /// A simple button for triggering the globally configured IProvider to sign in and out.
14 | ///
15 | public partial class LoginButton : UserControl
16 | {
17 | public LoginButton()
18 | {
19 | InitializeComponent();
20 |
21 | ProviderManager.Instance.ProviderStateChanged += (s, e) => UpdateState();
22 | UpdateState();
23 | }
24 |
25 | private void UpdateState()
26 | {
27 | var provider = ProviderManager.Instance.GlobalProvider;
28 | if (provider == null || provider.State == ProviderState.Loading)
29 | {
30 | MyButton.Content = "Sign in";
31 | IsEnabled = false;
32 | return;
33 | }
34 |
35 | switch (provider.State)
36 | {
37 | case ProviderState.SignedIn:
38 | MyButton.Content = "Sign out";
39 | break;
40 |
41 | case ProviderState.SignedOut:
42 | MyButton.Content = "Sign in";
43 | break;
44 | }
45 |
46 | IsEnabled = true;
47 | }
48 |
49 | private void MyButton_Click(object sender, RoutedEventArgs e)
50 | {
51 | Application.Current.Dispatcher.Invoke(new Action(() =>
52 | {
53 | var provider = ProviderManager.Instance.GlobalProvider;
54 | if (provider != null)
55 | {
56 | switch (provider.State)
57 | {
58 | case ProviderState.SignedOut:
59 | provider.SignInAsync();
60 | break;
61 |
62 | case ProviderState.SignedIn:
63 | provider.SignOutAsync();
64 | break;
65 | }
66 | }
67 | }));
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/Samples/WpfNetWindowsMsalProviderSample/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/Samples/WpfNetWindowsMsalProviderSample/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using CommunityToolkit.Authentication;
6 | using CommunityToolkit.Graph.Extensions;
7 | using System.Windows;
8 |
9 | namespace WpfNetWindowsMsalProviderSample
10 | {
11 | ///
12 | /// Interaction logic for MainWindow.xaml
13 | ///
14 | public partial class MainWindow : Window
15 | {
16 | public MainWindow()
17 | {
18 | InitializeComponent();
19 |
20 | ProviderManager.Instance.ProviderStateChanged += OnProviderStateChanged;
21 | }
22 |
23 | private async void OnProviderStateChanged(object sender, ProviderStateChangedEventArgs e)
24 | {
25 | if (e.NewState == ProviderState.SignedIn)
26 | {
27 | SignedInUserTextBlock.Text = "Signed in as...";
28 |
29 | var graphClient = ProviderManager.Instance.GlobalProvider.GetClient();
30 | var me = await graphClient.Me.Request().GetAsync();
31 |
32 | SignedInUserTextBlock.Text = "Signed in as: " + me.DisplayName;
33 | }
34 | else
35 | {
36 | SignedInUserTextBlock.Text = "Please sign in.";
37 | }
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Samples/WpfNetWindowsMsalProviderSample/README.md:
--------------------------------------------------------------------------------
1 | # MsalProvider Authentication Sample for .NET 6.0 WPF apps
2 |
3 | This sample demonstrates how to configure the MsalProvider to authenticate consumer MSA and organizational AAD accounts in your apps.
4 |
5 | ```
6 | string ClientId = "YOUR-CLIENT-ID-HERE";
7 | string[] Scopes = new string[] { "User.Read" };
8 |
9 | var provider = new MsalProvider(ClientId, Scopes, null, false, true);
10 |
11 | // Configure the token cache storage for non-UWP applications.
12 | var storageProperties = new StorageCreationPropertiesBuilder(CacheConfig.CacheFileName, CacheConfig.CacheDir)
13 | .WithLinuxKeyring(
14 | CacheConfig.LinuxKeyRingSchema,
15 | CacheConfig.LinuxKeyRingCollection,
16 | CacheConfig.LinuxKeyRingLabel,
17 | CacheConfig.LinuxKeyRingAttr1,
18 | CacheConfig.LinuxKeyRingAttr2)
19 | .WithMacKeyChain(
20 | CacheConfig.KeyChainServiceName,
21 | CacheConfig.KeyChainAccountName)
22 | .Build();
23 | await provider.InitTokenCacheAsync(storageProperties);
24 |
25 | ProviderManager.Instance.GlobalProvider = provider;
26 |
27 | await provider.TrySilentSignInAsync();
28 | ```
29 |
30 | It uses an IProvider implementation called MsalProvider, which leverages the official Microsoft Authentication Library (MSAL)
31 | to enable authentication for MSA and AAD accounts.
32 |
--------------------------------------------------------------------------------
/Samples/WpfNetWindowsMsalProviderSample/WpfNetWindowsMsalProviderSample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | WinExe
5 | net6.0-windows10.0.17763.0
6 | true
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/UnitTests/UnitTests.UWP/Assets/LockScreenLogo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/UnitTests/UnitTests.UWP/Assets/LockScreenLogo.scale-200.png
--------------------------------------------------------------------------------
/UnitTests/UnitTests.UWP/Assets/SplashScreen.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/UnitTests/UnitTests.UWP/Assets/SplashScreen.scale-200.png
--------------------------------------------------------------------------------
/UnitTests/UnitTests.UWP/Assets/Square150x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/UnitTests/UnitTests.UWP/Assets/Square150x150Logo.scale-200.png
--------------------------------------------------------------------------------
/UnitTests/UnitTests.UWP/Assets/Square44x44Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/UnitTests/UnitTests.UWP/Assets/Square44x44Logo.scale-200.png
--------------------------------------------------------------------------------
/UnitTests/UnitTests.UWP/Assets/Square44x44Logo.targetsize-24_altform-unplated.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/UnitTests/UnitTests.UWP/Assets/Square44x44Logo.targetsize-24_altform-unplated.png
--------------------------------------------------------------------------------
/UnitTests/UnitTests.UWP/Assets/StoreLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/UnitTests/UnitTests.UWP/Assets/StoreLogo.png
--------------------------------------------------------------------------------
/UnitTests/UnitTests.UWP/Assets/Wide310x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/UnitTests/UnitTests.UWP/Assets/Wide310x150Logo.scale-200.png
--------------------------------------------------------------------------------
/UnitTests/UnitTests.UWP/Package.appxmanifest:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
11 |
12 |
13 |
14 |
15 | UnitTests.UWP
16 | Microsoft
17 | Assets\StoreLogo.png
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
31 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/UnitTests/UnitTests.UWP/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System.Reflection;
6 | using System.Runtime.InteropServices;
7 |
8 | // General Information about an assembly is controlled through the following
9 | // set of attributes. Change these attribute values to modify the information
10 | // associated with an assembly.
11 | [assembly: AssemblyTitle("UnitTests")]
12 | [assembly: AssemblyDescription("")]
13 | [assembly: AssemblyConfiguration("")]
14 | [assembly: AssemblyCompany("")]
15 | [assembly: AssemblyProduct("UnitTests")]
16 | [assembly: AssemblyCopyright("Copyright © 2021")]
17 | [assembly: AssemblyTrademark("")]
18 | [assembly: AssemblyCulture("")]
19 | [assembly: AssemblyMetadata("TargetPlatform", "UAP")]
20 |
21 | [assembly: ComVisible(false)]
--------------------------------------------------------------------------------
/UnitTests/UnitTests.UWP/Properties/Default.rd.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/UnitTests/UnitTests.UWP/SmokeTest.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using Microsoft.VisualStudio.TestTools.UnitTesting;
6 |
7 | namespace UnitTests.UWP
8 | {
9 | ///
10 | /// A super basic dummy test to make sure the test harness is prepared properly and ready for more tests.
11 | ///
12 | [TestClass]
13 | public class SmokeTest
14 | {
15 | [TestCategory("SmokeTest")]
16 | [TestMethod]
17 | public void TrueIsTrue()
18 | {
19 | Assert.IsTrue(true);
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/UnitTests/UnitTests.UWP/UnitTestApp.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/UnitTests/UnitTests.UWP/VisualUITestBase.cs:
--------------------------------------------------------------------------------
1 | // Licensed to the .NET Foundation under one or more agreements.
2 | // The .NET Foundation licenses this file to you under the MIT license.
3 | // See the LICENSE file in the project root for more information.
4 |
5 | using System;
6 | using System.Threading.Tasks;
7 | using Microsoft.Toolkit.Uwp;
8 | using Microsoft.Toolkit.Uwp.UI.Helpers;
9 | using Microsoft.VisualStudio.TestTools.UnitTesting;
10 | using Windows.UI.Xaml;
11 |
12 | namespace UnitTests.UWP
13 | {
14 | ///
15 | /// Base class to be used in API tests which require UI layout or rendering to occur first.
16 | /// For more E2E scenarios or testing components for user interation, see integration test suite instead.
17 | /// Use this class when an API needs direct access to test functions of the UI itself in more simplistic scenarios (i.e. visual tree helpers).
18 | ///
19 | public class VisualUITestBase
20 | {
21 | ///
22 | /// Sets the content of the test app to a simple to load into the visual tree.
23 | /// Waits for that element to be loaded and rendered before returning.
24 | ///
25 | /// Content to set in test app.
26 | /// When UI is loaded.
27 | protected Task SetTestContentAsync(FrameworkElement content)
28 | {
29 | return App.DispatcherQueue.EnqueueAsync(() =>
30 | {
31 | var taskCompletionSource = new TaskCompletionSource();
32 |
33 | async void Callback(object sender, RoutedEventArgs args)
34 | {
35 | content.Loaded -= Callback;
36 |
37 | // Wait for first Render pass
38 | await CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync(() => { });
39 |
40 | taskCompletionSource.SetResult(true);
41 | }
42 |
43 | // Going to wait for our original content to unload
44 | content.Loaded += Callback;
45 |
46 | // Trigger that now
47 | try
48 | {
49 | App.ContentRoot = content;
50 | }
51 | catch (Exception e)
52 | {
53 | taskCompletionSource.SetException(e);
54 | }
55 |
56 | return taskCompletionSource.Task;
57 | });
58 | }
59 |
60 | [TestCleanup]
61 | public async Task Cleanup()
62 | {
63 | var taskCompletionSource = new TaskCompletionSource();
64 |
65 | await App.DispatcherQueue.EnqueueAsync(() =>
66 | {
67 | // If we didn't set our content we don't have to do anything but complete here.
68 | if (App.ContentRoot is null)
69 | {
70 | taskCompletionSource.SetResult(true);
71 | return;
72 | }
73 |
74 | // Going to wait for our original content to unload
75 | App.ContentRoot.Unloaded += (_, _) => taskCompletionSource.SetResult(true);
76 |
77 | // Trigger that now
78 | App.ContentRoot = null;
79 | });
80 |
81 | await taskCompletionSource.Task;
82 | }
83 | }
84 | }
--------------------------------------------------------------------------------
/azure-pipelines.yml:
--------------------------------------------------------------------------------
1 | # Control which branches get CI triggers (defaults to all branches if this parameter is not set)
2 | trigger:
3 | - main
4 | - dev/*
5 | - rel/*
6 |
7 | # Specify the target branches for pull request builds
8 | pr:
9 | - main
10 | - dev/*
11 | - rel/*
12 |
13 | # Microsoft-hosted agent pool for Visual Studio 2022
14 | pool:
15 | vmImage: windows-2022
16 |
17 | steps:
18 | # Setup Environment Variables
19 | - task: BatchScript@1
20 | inputs:
21 | filename: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\Common7\\Tools\\VsDevCmd.bat"
22 | arguments: -no_logo
23 | modifyEnvironment: true
24 | displayName: Setup Environment Variables
25 |
26 | # Install Nuget Tool Installer
27 | - task: NuGetToolInstaller@0
28 | displayName: Use NuGet 5.11.x
29 | inputs:
30 | versionSpec: 5.11.x
31 |
32 | # Install NBGV Tool
33 | - task: DotNetCoreCLI@2
34 | inputs:
35 | command: custom
36 | custom: tool
37 | arguments: install --tool-path . nbgv
38 | displayName: Install NBGV tool
39 |
40 | # Set cloud build variables
41 | - script: nbgv cloud
42 | displayName: Set Version
43 |
44 | # Install Windows SDK 18362 (minimum compatible sdk)
45 | - powershell: .\build\Install-WindowsSdkISO.ps1 22621
46 | displayName: Insider SDK
47 |
48 | # restore & build solution
49 | - script: msbuild -r -target:Build -p:Configuration=CI -p:GenerateLibraryLayout=true
50 | displayName: Restore & Build solution
51 |
52 | # run tests
53 | ### Tests require logging in, so aren't achievable in CI with current setup. Should ask MSAL/Graph team how they mock in future.
54 | ### Leaving this here as if UnitTests.Uwp area built, this should run them.
55 | #- script: vstest.console.exe ./UnitTests/**/*.appxrecipe /Framework:FrameworkUap10 /logger:"trx;LogFileName=VsTestResultsUwp.trx"
56 | # displayName: Unit Tests
57 |
58 | # publish results
59 | #- task: PublishTestResults@2
60 | # inputs:
61 | # testResultsFormat: 'VSTest'
62 | # testResultsFiles: '**/VsTestResults*.trx'
63 | # displayName: Publish Test Results
64 | # condition: always()
65 |
66 | # pack solution
67 | - script: msbuild -target:Pack -p:Configuration=CI -p:GenerateLibraryLayout=true -p:PackageOutputPath=..\bin\nupkg
68 | displayName: Pack solution
69 |
70 | # Sign Nuget package
71 | - task: PowerShell@2
72 | displayName: Authenticode Sign Packages
73 | inputs:
74 | filePath: build/Sign-Package.ps1
75 | env:
76 | SignClientUser: $(SignClientUser)
77 | SignClientSecret: $(SignClientSecret)
78 | ArtifactDirectory: bin\nupkg
79 | condition: and(succeeded(), not(eq(variables['build.reason'], 'PullRequest')), not(eq(variables['SignClientSecret'], '')), not(eq(variables['SignClientUser'], '')))
80 |
81 | # Publish nuget package
82 | - task: PublishBuildArtifacts@1
83 | displayName: Publish Package Artifacts
84 | inputs:
85 | pathToPublish: .\bin\nupkg
86 | artifactName: Packages
87 |
--------------------------------------------------------------------------------
/build/Install-WindowsSDK.ps1:
--------------------------------------------------------------------------------
1 | ## Licensed to the .NET Foundation under one or more agreements.
2 | ## The .NET Foundation licenses this file to you under the MIT license.
3 | ## See the LICENSE file in the project root for more information.
4 |
5 | mkdir c:\winsdktemp
6 |
7 | $client = new-object System.Net.WebClient
8 | $client.DownloadFile("https://go.microsoft.com/fwlink/p/?linkid=870807","c:\winsdktemp\winsdksetup.exe")
9 |
10 | Start-Process -Wait "c:\winsdktemp\winsdksetup.exe" "/features OptionId.UWPCpp /q"
--------------------------------------------------------------------------------
/build/Sign-Package.ps1:
--------------------------------------------------------------------------------
1 | ## Licensed to the .NET Foundation under one or more agreements.
2 | ## The .NET Foundation licenses this file to you under the MIT license.
3 | ## See the LICENSE file in the project root for more information.
4 |
5 | $currentDirectory = split-path $MyInvocation.MyCommand.Definition
6 |
7 | # See if we have the ClientSecret available
8 | if([string]::IsNullOrEmpty($Env:SignClientSecret)){
9 | Write-Host "Client Secret not found, not signing packages"
10 | return;
11 | }
12 |
13 | dotnet tool install --tool-path . SignClient
14 |
15 | # Setup Variables we need to pass into the sign client tool
16 |
17 | $appSettings = "$currentDirectory\SignClientSettings.json"
18 |
19 | $nupkgs = gci $Env:ArtifactDirectory\*.nupkg -recurse | Select -ExpandProperty FullName
20 |
21 | foreach ($nupkg in $nupkgs){
22 | Write-Host "Submitting $nupkg for signing"
23 |
24 | .\SignClient 'sign' -c $appSettings -i $nupkg -r $Env:SignClientUser -s $Env:SignClientSecret -n 'Windows Community Toolkit' -d 'Windows Community Toolkit' -u 'https://developer.microsoft.com/en-us/windows/uwp-community-toolkit'
25 | if ($LASTEXITCODE -ne 0) {
26 | exit 1
27 | }
28 | Write-Host "Finished signing $nupkg"
29 | }
30 |
31 | Write-Host "Sign-package complete"
--------------------------------------------------------------------------------
/build/SignClientSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "SignClient": {
3 | "AzureAd": {
4 | "AADInstance": "https://login.microsoftonline.com/",
5 | "ClientId": "c248d68a-ba6f-4aa9-8a68-71fe872063f8",
6 | "TenantId": "16076fdc-fcc1-4a15-b1ca-32c9a255900e"
7 | },
8 | "Service": {
9 | "Url": "https://codesign.dotnetfoundation.org/",
10 | "ResourceId": "https://SignService/3c30251f-36f3-490b-a955-520addb85001"
11 | }
12 | }
13 | }
--------------------------------------------------------------------------------
/build/Windows.Toolkit.Common.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | .NET Foundation
5 | Microsoft.Toolkit
6 | Windows Community Toolkit
7 | Windows;Community;Toolkit;WCT;Graph;Authentication;
8 | MIT
9 | true
10 | (c) .NET Foundation and Contributors. All rights reserved.
11 | https://github.com/CommunityToolkit/Graph-Controls
12 | https://github.com/CommunityToolkit/Graph-Controls/releases
13 | Icon.png
14 | https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/main/build/nuget.png
15 |
16 |
17 |
18 | Strict
19 | Disable
20 | Latest
21 | en-US
22 | true
23 |
24 |
25 |
26 | 10.0
27 | 22621
28 | 17763
29 |
30 |
31 |
32 | $(MSBuildProjectName.Contains('.Sample'))
33 | $(MSBuildProjectName.Contains('Test'))
34 | $(MSBuildProjectName.Contains('.Uwp'))
35 | True
36 | False
37 |
38 |
39 |
40 | true
41 | true
42 | $(TF_BUILD)
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/build/Windows.Toolkit.Common.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | $(Product) Asset
6 |
7 |
8 |
9 | $(CommonTags);.NET
10 | $(CommonTags);UWP
11 | $(CommonTags);$(PackageTags)
12 | $(CommonTags)
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/build/Windows.Toolkit.UWP.Build.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | $(TargetPlatformBaseVersion).$(TargetPlatformRevision).0
6 | $(TargetPlatformBaseVersion).$(TargetPlatformMinRevision).0
7 | Portable
8 |
9 |
10 |
11 |
12 | Windows Desktop Extensions for the UWP
13 |
14 |
15 | Windows Mobile Extensions for the UWP
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/build/Windows.Toolkit.Workarounds.Xaml.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/build/nuget.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/build/nuget.png
--------------------------------------------------------------------------------
/global.json:
--------------------------------------------------------------------------------
1 | {
2 | "msbuild-sdks": {
3 | "MSBuild.Sdk.Extras": "3.0.44"
4 | },
5 | "sdk": {
6 | "version": "6.0.400",
7 | "rollForward": "latestFeature"
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/nuget.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/settings.xamlstyler:
--------------------------------------------------------------------------------
1 | {
2 | "AttributesTolerance": 1,
3 | "KeepFirstAttributeOnSameLine": true,
4 | "MaxAttributeCharactersPerLine": 0,
5 | "MaxAttributesPerLine": 1,
6 | "NewlineExemptionElements": "RadialGradientBrush, GradientStop, LinearGradientBrush, ScaleTransform, SkewTransform, RotateTransform, TranslateTransform, Trigger, Condition, Setter",
7 | "SeparateByGroups": false,
8 | "AttributeIndentation": 0,
9 | "AttributeIndentationStyle": 1,
10 | "RemoveDesignTimeReferences": false,
11 | "EnableAttributeReordering": true,
12 | "AttributeOrderingRuleGroups": [
13 | "x:Class",
14 | "xmlns, xmlns:x",
15 | "xmlns:*",
16 | "x:Key, Key, x:Name, Name, x:Uid, Uid, Title",
17 | "Grid.Row, Grid.RowSpan, Grid.Column, Grid.ColumnSpan, Canvas.Left, Canvas.Top, Canvas.Right, Canvas.Bottom",
18 | "Width, Height, MinWidth, MinHeight, MaxWidth, MaxHeight",
19 | "Margin, Padding, HorizontalAlignment, VerticalAlignment, HorizontalContentAlignment, VerticalContentAlignment, Panel.ZIndex",
20 | "*:*, *",
21 | "PageSource, PageIndex, Offset, Color, TargetName, Property, Value, StartPoint, EndPoint",
22 | "mc:Ignorable, d:IsDataSource, d:LayoutOverrides, d:IsStaticText",
23 | "Storyboard.*, From, To, Duration"
24 | ],
25 | "FirstLineAttributes": "",
26 | "OrderAttributesByName": true,
27 | "PutEndingBracketOnNewLine": false,
28 | "RemoveEndingTagOfEmptyElement": true,
29 | "SpaceBeforeClosingSlash": true,
30 | "RootElementLineBreakRule": 0,
31 | "ReorderVSM": 2,
32 | "ReorderGridChildren": false,
33 | "ReorderCanvasChildren": false,
34 | "ReorderSetters": 0,
35 | "FormatMarkupExtension": true,
36 | "NoNewLineMarkupExtensions": "x:Bind, Binding",
37 | "ThicknessSeparator": 2,
38 | "ThicknessAttributes": "Margin, Padding, BorderThickness, ThumbnailClipMargin",
39 | "FormatOnSave": true,
40 | "CommentPadding": 2,
41 | "IndentSize": 4
42 | }
43 |
--------------------------------------------------------------------------------
/toolkit.public.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/toolkit.public.snk
--------------------------------------------------------------------------------
/toolkit.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CommunityToolkit/Graph-Controls/9fc2a992a04596562178dce14e6d01e1b32b374b/toolkit.snk
--------------------------------------------------------------------------------
/version.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "7.1.3-build.{height}",
3 | "publicReleaseRefSpec": [
4 | "^refs/heads/main$", // we release out of main
5 | "^refs/heads/dev$", // we release out of dev
6 | "^refs/heads/rel/\\d+\\.\\d+\\.\\d+" // we also release branches starting with rel/N.N.N
7 | ],
8 | "nugetPackageVersion": {
9 | "semVer": 2
10 | },
11 | "cloudBuild": {
12 | "buildNumber": {
13 | "enabled": false
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------