├── .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 | 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 |