From b15907ff726629b5333ab48e318d60b6117029a0 Mon Sep 17 00:00:00 2001 From: Shane Weaver Date: Tue, 9 Feb 2021 15:07:58 -0800 Subject: [PATCH 01/16] Adding WindowsProvider --- .../Microsoft.Toolkit.Graph.Controls.csproj | 7 + .../Providers/GraphExtensions.cs | 62 ++++ .../Providers/IGraphConfig.cs | 13 + .../Providers/MockConfig.cs | 17 ++ .../Providers/MsalConfig.cs | 35 +++ .../Providers/QuickCreate.cs | 24 +- .../Providers/WindowsConfig.cs | 30 ++ .../Providers/WindowsProvider.cs | 286 ++++++++++++++++++ .../Extensions/GraphExtensions.cs | 3 +- .../Providers/BaseProvider.cs | 62 ++++ .../Providers/IProvider.cs | 2 +- .../Providers/MockProvider.cs | 4 +- .../Providers/MsalProvider.cs | 4 +- .../Providers/ProviderManager.cs | 2 +- ...gs.cs => ProviderStateChangedEventArgs.cs} | 6 +- SampleTest/MainPage.xaml | 17 +- SampleTest/MainPage.xaml.cs | 12 + SampleTest/Package.appxmanifest | 10 +- SampleTest/SampleTest.csproj | 1 + 19 files changed, 566 insertions(+), 31 deletions(-) create mode 100644 Microsoft.Toolkit.Graph.Controls/Providers/GraphExtensions.cs create mode 100644 Microsoft.Toolkit.Graph.Controls/Providers/IGraphConfig.cs create mode 100644 Microsoft.Toolkit.Graph.Controls/Providers/MockConfig.cs create mode 100644 Microsoft.Toolkit.Graph.Controls/Providers/MsalConfig.cs create mode 100644 Microsoft.Toolkit.Graph.Controls/Providers/WindowsConfig.cs create mode 100644 Microsoft.Toolkit.Graph.Controls/Providers/WindowsProvider.cs create mode 100644 Microsoft.Toolkit.Graph/Providers/BaseProvider.cs rename Microsoft.Toolkit.Graph/Providers/{StateChangedEventArgs.cs => ProviderStateChangedEventArgs.cs} (80%) diff --git a/Microsoft.Toolkit.Graph.Controls/Microsoft.Toolkit.Graph.Controls.csproj b/Microsoft.Toolkit.Graph.Controls/Microsoft.Toolkit.Graph.Controls.csproj index 75cb0a1..dc1b2cb 100644 --- a/Microsoft.Toolkit.Graph.Controls/Microsoft.Toolkit.Graph.Controls.csproj +++ b/Microsoft.Toolkit.Graph.Controls/Microsoft.Toolkit.Graph.Controls.csproj @@ -20,6 +20,13 @@ AnyCPU;ARM;ARM64;x64;x86 + + + + + + + diff --git a/Microsoft.Toolkit.Graph.Controls/Providers/GraphExtensions.cs b/Microsoft.Toolkit.Graph.Controls/Providers/GraphExtensions.cs new file mode 100644 index 0000000..fd43c39 --- /dev/null +++ b/Microsoft.Toolkit.Graph.Controls/Providers/GraphExtensions.cs @@ -0,0 +1,62 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Linq; +using Windows.UI.Xaml; + +namespace Microsoft.Toolkit.Graph.Providers +{ + /// + /// + /// + public static class GraphExtensions + { + /// + /// Gets the Graph Config property value. + /// + /// + /// + public static IGraphConfig GetGraphConfig(DependencyObject target) + { + return (IGraphConfig)target.GetValue(GraphConfigProperty); + } + + /// + /// Sets the GraphConfig property value. + /// + /// + /// + public static void SetGraphConfig(DependencyObject target, IGraphConfig value) + { + target.SetValue(GraphConfigProperty, value); + } + + /// + /// Identifies the dependency property. + /// + /// + /// The identifier for the dependency property. + /// + public static readonly DependencyProperty GraphConfigProperty = + DependencyProperty.RegisterAttached("GraphConfig", typeof(IGraphConfig), typeof(FrameworkElement), new PropertyMetadata(null, OnGraphConfigChanged)); + + private static async void OnGraphConfigChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) + { + IGraphConfig config = GetGraphConfig(sender); + + if (config is MockConfig mockConfig) + { + ProviderManager.Instance.GlobalProvider = new MockProvider(mockConfig.SignedIn); + } + else if (config is MsalConfig msalConfig) + { + ProviderManager.Instance.GlobalProvider = await QuickCreate.CreateMsalProviderAsync(msalConfig); + } + else if (config is WindowsConfig winConfig) + { + ProviderManager.Instance.GlobalProvider = await QuickCreate.CreateWindowsProviderAsync(winConfig); + } + } + } +} diff --git a/Microsoft.Toolkit.Graph.Controls/Providers/IGraphConfig.cs b/Microsoft.Toolkit.Graph.Controls/Providers/IGraphConfig.cs new file mode 100644 index 0000000..49c5866 --- /dev/null +++ b/Microsoft.Toolkit.Graph.Controls/Providers/IGraphConfig.cs @@ -0,0 +1,13 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Microsoft.Toolkit.Graph.Providers +{ + /// + /// + /// + public interface IGraphConfig + { + } +} diff --git a/Microsoft.Toolkit.Graph.Controls/Providers/MockConfig.cs b/Microsoft.Toolkit.Graph.Controls/Providers/MockConfig.cs new file mode 100644 index 0000000..4877b34 --- /dev/null +++ b/Microsoft.Toolkit.Graph.Controls/Providers/MockConfig.cs @@ -0,0 +1,17 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Microsoft.Toolkit.Graph.Providers +{ + /// + /// + /// + public class MockConfig : IGraphConfig + { + /// + /// + /// + public bool SignedIn { get; set; } = true; + } +} diff --git a/Microsoft.Toolkit.Graph.Controls/Providers/MsalConfig.cs b/Microsoft.Toolkit.Graph.Controls/Providers/MsalConfig.cs new file mode 100644 index 0000000..b736b6b --- /dev/null +++ b/Microsoft.Toolkit.Graph.Controls/Providers/MsalConfig.cs @@ -0,0 +1,35 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Microsoft.Toolkit.Graph.Providers +{ + /// + /// + /// + public class MsalConfig : IGraphConfig + { + /// + /// Gets or sets the Client ID (the unique application (client) ID assigned to your app by Azure AD when the app was registered). + /// + /// + /// For details about how to register an app and get a client ID, + /// see the Register an app quick start. + /// + public string ClientId { get; set; } + + /// + /// Gets or sets the redirect URI (the URI the identity provider will send the security tokens back to). + /// + public string RedirectUri { get; set; } = "https://login.microsoftonline.com/common/oauth2/nativeclient"; + + /// + /// Gets or sets the list of Scopes (permissions) to request on initial login. + /// + /// + /// This list can be modified by controls which require specific scopes to function. + /// This will aid in requesting all scopes required by controls used before login is initiated, if using the LoginButton. + /// + public ScopeSet Scopes { get; set; } + } +} diff --git a/Microsoft.Toolkit.Graph.Controls/Providers/QuickCreate.cs b/Microsoft.Toolkit.Graph.Controls/Providers/QuickCreate.cs index b9fdfe7..616cf8a 100644 --- a/Microsoft.Toolkit.Graph.Controls/Providers/QuickCreate.cs +++ b/Microsoft.Toolkit.Graph.Controls/Providers/QuickCreate.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Linq; using System.Reflection; using System.Threading.Tasks; using Microsoft.Graph.Auth; @@ -34,23 +35,28 @@ public static class QuickCreate /// RedirectUri for auth response. /// List of Scopes to initially request. /// New reference. - public static async Task CreateMsalProviderAsync(string clientid, string redirectUri = "https://login.microsoftonline.com/common/oauth2/nativeclient", string[] scopes = null) + public static async Task CreateMsalProviderAsync(MsalConfig config) { - var client = PublicClientApplicationBuilder.Create(clientid) + var client = PublicClientApplicationBuilder.Create(config.ClientId) .WithAuthority(AzureCloudInstance.AzurePublic, AadAuthorityAudience.AzureAdAndPersonalMicrosoftAccount) - .WithRedirectUri(redirectUri) + .WithRedirectUri(config.RedirectUri) .WithClientName(ProviderManager.ClientName) .WithClientVersion(Assembly.GetExecutingAssembly().GetName().Version.ToString()) .Build(); - if (scopes == null) - { - scopes = new string[] { string.Empty }; - } - - var provider = new InteractiveAuthenticationProvider(client, scopes); + var provider = new InteractiveAuthenticationProvider(client, config.Scopes); return await MsalProvider.CreateAsync(client, provider); } + + /// + /// + /// + /// + /// + public static async Task CreateWindowsProviderAsync(WindowsConfig config) + { + return await WindowsProvider.CreateAsync(config.ClientId, config.Scopes.ToArray()); + } } } diff --git a/Microsoft.Toolkit.Graph.Controls/Providers/WindowsConfig.cs b/Microsoft.Toolkit.Graph.Controls/Providers/WindowsConfig.cs new file mode 100644 index 0000000..dc4d67a --- /dev/null +++ b/Microsoft.Toolkit.Graph.Controls/Providers/WindowsConfig.cs @@ -0,0 +1,30 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Microsoft.Toolkit.Graph.Providers +{ + /// + /// Basic configuration for talking to the Graph. + /// + public class WindowsConfig : IGraphConfig + { + /// + /// Gets or sets the Client ID (the unique application (client) ID assigned to your app by Azure AD when the app was registered). + /// + /// + /// For details about how to register an app and get a client ID, + /// see the Register an app quick start. + /// + public string ClientId { get; set; } + + /// + /// Gets or sets the list of Scopes (permissions) to request on initial login. + /// + /// + /// This list can be modified by controls which require specific scopes to function. + /// This will aid in requesting all scopes required by controls used before login is initiated, if using the LoginButton. + /// + public ScopeSet Scopes { get; set; } = new ScopeSet { "User.Read", "User.ReadBasic.All" }; + } +} diff --git a/Microsoft.Toolkit.Graph.Controls/Providers/WindowsProvider.cs b/Microsoft.Toolkit.Graph.Controls/Providers/WindowsProvider.cs new file mode 100644 index 0000000..aaa0f26 --- /dev/null +++ b/Microsoft.Toolkit.Graph.Controls/Providers/WindowsProvider.cs @@ -0,0 +1,286 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Diagnostics; +using System.Linq; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Threading.Tasks; +using Microsoft.Graph; +using Windows.Security.Authentication.Web; +using Windows.Security.Authentication.Web.Core; +using Windows.UI.ApplicationSettings; + +namespace Microsoft.Toolkit.Graph.Providers +{ + /// + /// A provider for leveraging Windows system authentication. + /// + public class WindowsProvider : BaseProvider + { + private struct AuthenticatedUser + { + public Windows.Security.Credentials.PasswordCredential TokenCredential { get; private set; } + + public string GetUserName() + { + return TokenCredential?.UserName; + } + + public string GetToken() + { + return TokenCredential?.Password; + } + + public AuthenticatedUser(Windows.Security.Credentials.PasswordCredential tokenCredential) + { + TokenCredential = tokenCredential; + } + } + + private const string TokenCredentialResourceName = "WindowsProviderToken"; + private const string WebAccountProviderId = "https://login.microsoft.com"; + private static readonly string[] DefaultScopes = new string[] { "user.read" }; + private static readonly string GraphResourceProperty = "https://graph.microsoft.com"; + + /// + /// Gets the redirect uri value based on the current app callback uri. + /// + public static string RedirectUri => string.Format("ms-appx-web://Microsoft.AAD.BrokerPlugIn/{0}", WebAuthenticationBroker.GetCurrentApplicationCallbackUri().Host.ToUpper()); + + private AccountsSettingsPane _currentPane; + private AuthenticatedUser? _currentUser; + private string[] _scopes; + private string _clientId; + + /// + /// Creates a new instance of the WindowsProvider and attempts to sign in silently. + /// + /// + /// + /// A new instance of a WindowsProvider. + public static async Task CreateAsync(string clientId, string[] scopes) + { + var provider = new WindowsProvider(clientId, scopes); + + provider.Graph = new GraphServiceClient(provider); + + await provider.TrySilentSignInAsync(); + + return provider; + } + + private WindowsProvider(string clientId, string[] scopes = null) + { + _clientId = clientId ?? throw new ArgumentNullException(nameof(clientId)); + _currentPane = null; + _currentUser = null; + _scopes = scopes ?? DefaultScopes; + + Graph = new GraphServiceClient(new DelegateAuthenticationProvider(AuthenticateRequestAsync)); + + State = ProviderState.SignedOut; + } + + /// + /// Attempts to sign in the logged in user automatically. + /// + /// Success boolean. + public async Task TrySilentSignInAsync() + { + if (State == ProviderState.SignedIn) + { + return false; + } + + State = ProviderState.Loading; + + var tokenCredential = GetCredentialFromLocker(); + if (tokenCredential == null) + { + // There is no credential stored in the locker. + State = ProviderState.SignedOut; + return false; + } + + // Populate the password (aka token). + tokenCredential.RetrievePassword(); + + // Log the user in by storing the credential in memory. + _currentUser = new AuthenticatedUser(tokenCredential); + + try + { + var me = await Graph.Me.Request().GetAsync(); + + // Update the state to be signed in. + State = ProviderState.SignedIn; + return true; + } + catch + { + // Update the state to be signed in. + State = ProviderState.SignedOut; + return false; + } + } + + /// + public override Task LoginAsync() + { + if (State == ProviderState.SignedIn) + { + return Task.CompletedTask; + } + + State = ProviderState.Loading; + + if (_currentPane != null) + { + _currentPane.AccountCommandsRequested -= BuildPaneAsync; + } + + _currentPane = AccountsSettingsPane.GetForCurrentView(); + _currentPane.AccountCommandsRequested += BuildPaneAsync; + + AccountsSettingsPane.Show(); + return Task.CompletedTask; + } + + /// + public override Task LogoutAsync() + { + if (State == ProviderState.SignedOut) + { + return Task.CompletedTask; + } + + State = ProviderState.Loading; + + if (_currentPane != null) + { + _currentPane.AccountCommandsRequested -= BuildPaneAsync; + _currentPane = null; + } + + if (_currentUser != null) + { + // Remove the user info from the PaasswordVault + var vault = new Windows.Security.Credentials.PasswordVault(); + vault.Remove(_currentUser?.TokenCredential); + + _currentUser = null; + } + + State = ProviderState.SignedOut; + return Task.CompletedTask; + } + + /// + public override Task AuthenticateRequestAsync(HttpRequestMessage request) + { + // Append the token to the authorization header of any outgoing Graph requests. + var token = _currentUser?.GetToken(); + request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token); + return Task.CompletedTask; + } + + /// + /// https://docs.microsoft.com/en-us/windows/uwp/security/web-account-manager#build-the-account-settings-pane. + /// + private async void BuildPaneAsync(AccountsSettingsPane sender, AccountsSettingsPaneCommandsRequestedEventArgs args) + { + var deferral = args.GetDeferral(); + + try + { + // Providing nothing shows all accounts, providing authority shows only aad + var msaProvider = await WebAuthenticationCoreManager.FindAccountProviderAsync(WebAccountProviderId); + + if (msaProvider == null) + { + State = ProviderState.SignedOut; + return; + } + + var command = new WebAccountProviderCommand(msaProvider, GetTokenAsync); + args.WebAccountProviderCommands.Add(command); + } + catch + { + State = ProviderState.SignedOut; + } + finally + { + deferral.Complete(); + } + } + + private async void GetTokenAsync(WebAccountProviderCommand command) + { + // Build the token request + WebTokenRequest request = new WebTokenRequest(command.WebAccountProvider, string.Join(',', _scopes), _clientId); + request.Properties.Add("resource", GraphResourceProperty); + + // Get the results + WebTokenRequestResult result = await WebAuthenticationCoreManager.RequestTokenAsync(request); + + // Handle user cancellation + if (result.ResponseStatus == WebTokenRequestStatus.UserCancel) + { + State = ProviderState.SignedOut; + return; + } + + // Handle any errors + if (result.ResponseStatus != WebTokenRequestStatus.Success) + { + Debug.WriteLine(result.ResponseError.ErrorMessage); + State = ProviderState.SignedOut; + return; + } + + // Extract values from the results + var token = result.ResponseData[0].Token; + var account = result.ResponseData[0].WebAccount; + + // The UserName value may be null, but the Id is always present. + var userName = account.Id; + + // Save the user info to the PaasswordVault + var vault = new Windows.Security.Credentials.PasswordVault(); + var tokenCredential = new Windows.Security.Credentials.PasswordCredential(TokenCredentialResourceName, userName, token); + vault.Add(tokenCredential); + + // Set the current user object + _currentUser = new AuthenticatedUser(tokenCredential); + + // Update the state to be signed in. + State = ProviderState.SignedIn; + } + + private Windows.Security.Credentials.PasswordCredential GetCredentialFromLocker() + { + Windows.Security.Credentials.PasswordCredential credential = null; + + try + { + var vault = new Windows.Security.Credentials.PasswordVault(); + var credentialList = vault.FindAllByResource(TokenCredentialResourceName); + if (credentialList.Count > 0) + { + // We delete the credential upon logout, so only one user can be stored in the vault at a time. + credential = credentialList.First(); + } + } + catch + { + // FindAllByResource will throw an exception if the resource isn't found. + } + + return credential; + } + } +} diff --git a/Microsoft.Toolkit.Graph/Extensions/GraphExtensions.cs b/Microsoft.Toolkit.Graph/Extensions/GraphExtensions.cs index 9d7668a..67c65cd 100644 --- a/Microsoft.Toolkit.Graph/Extensions/GraphExtensions.cs +++ b/Microsoft.Toolkit.Graph/Extensions/GraphExtensions.cs @@ -66,8 +66,9 @@ public static async Task FindPersonAsync(this GraphSe .WithScopes(new string[] { "people.read" }) .GetAsync(); } - catch + catch (Exception e) { + } return new UserPeopleCollectionPage(); diff --git a/Microsoft.Toolkit.Graph/Providers/BaseProvider.cs b/Microsoft.Toolkit.Graph/Providers/BaseProvider.cs new file mode 100644 index 0000000..c684299 --- /dev/null +++ b/Microsoft.Toolkit.Graph/Providers/BaseProvider.cs @@ -0,0 +1,62 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Net.Http; +using System.Threading.Tasks; +using Microsoft.Graph; + +namespace Microsoft.Toolkit.Graph.Providers +{ + /// + /// A base construct for building Graph Providers on top of. + /// + public abstract class BaseProvider : IProvider + { + private ProviderState _state; + + /// + /// Gets or sets the current state of the provider. + /// + public ProviderState State + { + get => _state; + protected set + { + var oldState = _state; + var newState = value; + if (oldState != newState) + { + _state = newState; + StateChanged?.Invoke(this, new ProviderStateChangedEventArgs(oldState, newState)); + } + } + } + + /// + public event EventHandler StateChanged; + + /// + /// Gets or sets the service client instance for making Graph calls. + /// + public GraphServiceClient Graph { get; protected set; } + + /// + /// Initializes a new instance of the class. + /// + public BaseProvider() + { + _state = ProviderState.Loading; + } + + /// + public abstract Task LoginAsync(); + + /// + public abstract Task LogoutAsync(); + + /// + public abstract Task AuthenticateRequestAsync(HttpRequestMessage request); + } +} diff --git a/Microsoft.Toolkit.Graph/Providers/IProvider.cs b/Microsoft.Toolkit.Graph/Providers/IProvider.cs index ea59b80..c6a4f07 100644 --- a/Microsoft.Toolkit.Graph/Providers/IProvider.cs +++ b/Microsoft.Toolkit.Graph/Providers/IProvider.cs @@ -29,7 +29,7 @@ public interface IProvider : IAuthenticationProvider /// /// Event called when the login changes. /// - event EventHandler StateChanged; + event EventHandler StateChanged; /// /// Login the user. diff --git a/Microsoft.Toolkit.Graph/Providers/MockProvider.cs b/Microsoft.Toolkit.Graph/Providers/MockProvider.cs index a0d54ec..a26badd 100644 --- a/Microsoft.Toolkit.Graph/Providers/MockProvider.cs +++ b/Microsoft.Toolkit.Graph/Providers/MockProvider.cs @@ -38,7 +38,7 @@ private set var current = _state; _state = value; - StateChanged?.Invoke(this, new StateChangedEventArgs(current, _state)); + StateChanged?.Invoke(this, new ProviderStateChangedEventArgs(current, _state)); } } @@ -55,7 +55,7 @@ private set })); /// - public event EventHandler StateChanged; + public event EventHandler StateChanged; /// /// Initializes a new instance of the class. diff --git a/Microsoft.Toolkit.Graph/Providers/MsalProvider.cs b/Microsoft.Toolkit.Graph/Providers/MsalProvider.cs index 42c00bc..98a2e61 100644 --- a/Microsoft.Toolkit.Graph/Providers/MsalProvider.cs +++ b/Microsoft.Toolkit.Graph/Providers/MsalProvider.cs @@ -46,7 +46,7 @@ private set var current = _state; _state = value; - StateChanged?.Invoke(this, new StateChangedEventArgs(current, _state)); + StateChanged?.Invoke(this, new ProviderStateChangedEventArgs(current, _state)); } } @@ -54,7 +54,7 @@ private set public GraphServiceClient Graph { get; private set; } /// - public event EventHandler StateChanged; + public event EventHandler StateChanged; /// /// Initializes a new instance of the class. . diff --git a/Microsoft.Toolkit.Graph/Providers/ProviderManager.cs b/Microsoft.Toolkit.Graph/Providers/ProviderManager.cs index e417de0..301c912 100644 --- a/Microsoft.Toolkit.Graph/Providers/ProviderManager.cs +++ b/Microsoft.Toolkit.Graph/Providers/ProviderManager.cs @@ -72,7 +72,7 @@ private ProviderManager() // Use Instance } - private void ProviderStateChanged(object sender, StateChangedEventArgs e) + private void ProviderStateChanged(object sender, ProviderStateChangedEventArgs e) { ProviderUpdated?.Invoke(this, new ProviderUpdatedEventArgs(ProviderManagerChangedState.ProviderStateChanged)); } diff --git a/Microsoft.Toolkit.Graph/Providers/StateChangedEventArgs.cs b/Microsoft.Toolkit.Graph/Providers/ProviderStateChangedEventArgs.cs similarity index 80% rename from Microsoft.Toolkit.Graph/Providers/StateChangedEventArgs.cs rename to Microsoft.Toolkit.Graph/Providers/ProviderStateChangedEventArgs.cs index f2f65d0..37b1c95 100644 --- a/Microsoft.Toolkit.Graph/Providers/StateChangedEventArgs.cs +++ b/Microsoft.Toolkit.Graph/Providers/ProviderStateChangedEventArgs.cs @@ -9,14 +9,14 @@ namespace Microsoft.Toolkit.Graph.Providers /// /// event arguments. /// - public class StateChangedEventArgs : EventArgs + public class ProviderStateChangedEventArgs : EventArgs { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// Previous . /// Current . - public StateChangedEventArgs(ProviderState oldState, ProviderState newState) + public ProviderStateChangedEventArgs(ProviderState oldState, ProviderState newState) { OldState = oldState; NewState = newState; diff --git a/SampleTest/MainPage.xaml b/SampleTest/MainPage.xaml index 272dfa1..1990c52 100644 --- a/SampleTest/MainPage.xaml +++ b/SampleTest/MainPage.xaml @@ -1,8 +1,6 @@  - + - - + + + + + + + @@ -280,8 +283,8 @@ + ResponseType="graph:ChatMessage" + x:Name="TeamsMessagePresenter"> - + - SampleTest - mhawker + GraphControlsTestApp + Weaver Assets\StoreLogo.png diff --git a/SampleTest/SampleTest.csproj b/SampleTest/SampleTest.csproj index 1a0f4a0..231151f 100644 --- a/SampleTest/SampleTest.csproj +++ b/SampleTest/SampleTest.csproj @@ -131,6 +131,7 @@ + From e8c2a2feffe5c37dc9af9daadc63a1ef676ddebd Mon Sep 17 00:00:00 2001 From: Shane Weaver Date: Tue, 9 Feb 2021 15:50:55 -0800 Subject: [PATCH 02/16] Readding excluded files --- .../Microsoft.Toolkit.Graph.Controls.csproj | 7 ------ .../Providers/MsalConfig.cs | 2 +- .../Providers/QuickCreate.cs | 24 +++++++++++++------ 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Microsoft.Toolkit.Graph.Controls/Microsoft.Toolkit.Graph.Controls.csproj b/Microsoft.Toolkit.Graph.Controls/Microsoft.Toolkit.Graph.Controls.csproj index dc1b2cb..75cb0a1 100644 --- a/Microsoft.Toolkit.Graph.Controls/Microsoft.Toolkit.Graph.Controls.csproj +++ b/Microsoft.Toolkit.Graph.Controls/Microsoft.Toolkit.Graph.Controls.csproj @@ -20,13 +20,6 @@ AnyCPU;ARM;ARM64;x64;x86 - - - - - - - diff --git a/Microsoft.Toolkit.Graph.Controls/Providers/MsalConfig.cs b/Microsoft.Toolkit.Graph.Controls/Providers/MsalConfig.cs index b736b6b..713ef50 100644 --- a/Microsoft.Toolkit.Graph.Controls/Providers/MsalConfig.cs +++ b/Microsoft.Toolkit.Graph.Controls/Providers/MsalConfig.cs @@ -21,7 +21,7 @@ public class MsalConfig : IGraphConfig /// /// Gets or sets the redirect URI (the URI the identity provider will send the security tokens back to). /// - public string RedirectUri { get; set; } = "https://login.microsoftonline.com/common/oauth2/nativeclient"; + public string RedirectUri { get; set; } /// /// Gets or sets the list of Scopes (permissions) to request on initial login. diff --git a/Microsoft.Toolkit.Graph.Controls/Providers/QuickCreate.cs b/Microsoft.Toolkit.Graph.Controls/Providers/QuickCreate.cs index 616cf8a..879d2b0 100644 --- a/Microsoft.Toolkit.Graph.Controls/Providers/QuickCreate.cs +++ b/Microsoft.Toolkit.Graph.Controls/Providers/QuickCreate.cs @@ -23,6 +23,16 @@ namespace Microsoft.Toolkit.Graph.Providers /// public static class QuickCreate { + /// + /// Easily creates a from a config object. + /// + /// Msal configuraiton object. + /// New reference. + public static Task CreateMsalProviderAsync(MsalConfig config) + { + return CreateMsalProviderAsync(config.ClientId, config.RedirectUri, config.Scopes.ToArray()); + } + /// /// Easily creates a from a ClientId. /// @@ -35,25 +45,25 @@ public static class QuickCreate /// RedirectUri for auth response. /// List of Scopes to initially request. /// New reference. - public static async Task CreateMsalProviderAsync(MsalConfig config) + public static async Task CreateMsalProviderAsync(string clientid, string redirectUri = "https://login.microsoftonline.com/common/oauth2/nativeclient", string[] scopes = null) { - var client = PublicClientApplicationBuilder.Create(config.ClientId) + var client = PublicClientApplicationBuilder.Create(clientid) .WithAuthority(AzureCloudInstance.AzurePublic, AadAuthorityAudience.AzureAdAndPersonalMicrosoftAccount) - .WithRedirectUri(config.RedirectUri) + .WithRedirectUri(redirectUri) .WithClientName(ProviderManager.ClientName) .WithClientVersion(Assembly.GetExecutingAssembly().GetName().Version.ToString()) .Build(); - var provider = new InteractiveAuthenticationProvider(client, config.Scopes); + var provider = new InteractiveAuthenticationProvider(client, scopes); return await MsalProvider.CreateAsync(client, provider); } /// - /// + /// Easily creates a from a config object. /// - /// - /// + /// Windows configuration object. + /// New reference. public static async Task CreateWindowsProviderAsync(WindowsConfig config) { return await WindowsProvider.CreateAsync(config.ClientId, config.Scopes.ToArray()); From 9791ce04f0aa90f706a32941ed68786d2af26318 Mon Sep 17 00:00:00 2001 From: Shane Weaver Date: Tue, 9 Feb 2021 16:11:49 -0800 Subject: [PATCH 03/16] Updating nuget config --- nuget.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nuget.config b/nuget.config index 0718eda..a137674 100644 --- a/nuget.config +++ b/nuget.config @@ -2,6 +2,6 @@ - + \ No newline at end of file From b8f2ed074c447eeb6a7604fff5085571690f6e39 Mon Sep 17 00:00:00 2001 From: Shane Weaver Date: Thu, 11 Feb 2021 11:34:21 -0800 Subject: [PATCH 04/16] Removing references to behaviors --- .../CommonProviderBehaviorBase.Properties.cs | 74 ------------------- .../Providers/CommonProviderBehaviorBase.cs | 25 ------- .../Providers/Graph.cs | 69 +++++++++++++++++ .../Providers/GraphExtensions.cs | 62 ---------------- .../Providers/InteractiveProviderBehavior.cs | 63 ---------------- .../Providers/MockProviderBehavior.cs | 69 ----------------- SampleTest/MainPage.xaml | 8 +- 7 files changed, 71 insertions(+), 299 deletions(-) delete mode 100644 Microsoft.Toolkit.Graph.Controls/Providers/CommonProviderBehaviorBase.Properties.cs delete mode 100644 Microsoft.Toolkit.Graph.Controls/Providers/CommonProviderBehaviorBase.cs create mode 100644 Microsoft.Toolkit.Graph.Controls/Providers/Graph.cs delete mode 100644 Microsoft.Toolkit.Graph.Controls/Providers/GraphExtensions.cs delete mode 100644 Microsoft.Toolkit.Graph.Controls/Providers/InteractiveProviderBehavior.cs delete mode 100644 Microsoft.Toolkit.Graph.Controls/Providers/MockProviderBehavior.cs diff --git a/Microsoft.Toolkit.Graph.Controls/Providers/CommonProviderBehaviorBase.Properties.cs b/Microsoft.Toolkit.Graph.Controls/Providers/CommonProviderBehaviorBase.Properties.cs deleted file mode 100644 index e957366..0000000 --- a/Microsoft.Toolkit.Graph.Controls/Providers/CommonProviderBehaviorBase.Properties.cs +++ /dev/null @@ -1,74 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -#if DOTNET -using System.Windows; -#else -using Windows.UI.Xaml; -#endif - -#if DOTNET -namespace Microsoft.Toolkit.Wpf.Graph.Providers -#else -namespace Microsoft.Toolkit.Graph.Providers -#endif -{ - /// - /// Properties for . - /// - public partial class CommonProviderBehaviorBase - { - /// - /// Gets or sets the Client ID (the unique application (client) ID assigned to your app by Azure AD when the app was registered). - /// - /// - /// For details about how to register an app and get a client ID, - /// see the Register an app quick start. - /// - public string ClientId - { - get { return (string)GetValue(ClientIdProperty); } - set { SetValue(ClientIdProperty, value); } - } - - /// - /// Identifies the dependency property. - /// - /// - /// The identifier for the dependency property. - /// - public static readonly DependencyProperty ClientIdProperty = - DependencyProperty.Register(nameof(ClientId), typeof(string), typeof(CommonProviderBehaviorBase), new PropertyMetadata(string.Empty)); - - /// - /// Gets or sets the redirect URI (the URI the identity provider will send the security tokens back to). - /// - public string RedirectUri - { - get { return (string)GetValue(RedirectUriProperty); } - set { SetValue(RedirectUriProperty, value); } - } - - /// - /// Identifies the dependency property. - /// - /// - /// The identifier for the dependency property. - /// - public static readonly DependencyProperty RedirectUriProperty = -#if DOTNET - DependencyProperty.Register(nameof(RedirectUri), typeof(string), typeof(CommonProviderBehaviorBase), new PropertyMetadata("http://localhost")); //// https://aka.ms/msal-net-os-browser -#else - DependencyProperty.Register(nameof(RedirectUri), typeof(string), typeof(CommonProviderBehaviorBase), new PropertyMetadata("https://login.microsoftonline.com/common/oauth2/nativeclient")); -#endif - - /// - /// Gets or sets the list of Scopes (permissions) to request on initial login. - /// - /// - /// This list can be modified by controls which require specific scopes to function. This will aid in requesting all scopes required by controls used before login is initiated, if using the LoginButton. - /// - public ScopeSet Scopes { get; set; } = new ScopeSet { "User.Read", "User.ReadBasic.All" }; - } -} diff --git a/Microsoft.Toolkit.Graph.Controls/Providers/CommonProviderBehaviorBase.cs b/Microsoft.Toolkit.Graph.Controls/Providers/CommonProviderBehaviorBase.cs deleted file mode 100644 index bf8bd86..0000000 --- a/Microsoft.Toolkit.Graph.Controls/Providers/CommonProviderBehaviorBase.cs +++ /dev/null @@ -1,25 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -#if DOTNET -using System.Windows; -using Microsoft.Toolkit.Wpf.UI.Behaviors; -#else -using Microsoft.Toolkit.Uwp.UI.Behaviors; -using Windows.UI.Xaml; -#endif - -#if DOTNET -namespace Microsoft.Toolkit.Wpf.Graph.Providers -#else -namespace Microsoft.Toolkit.Graph.Providers -#endif -{ - /// - /// Provides a common base class for UWP XAML based provider wrappers to the Microsoft.Graph.Auth SDK. - /// - public abstract partial class CommonProviderBehaviorBase : BehaviorBase - { - } -} diff --git a/Microsoft.Toolkit.Graph.Controls/Providers/Graph.cs b/Microsoft.Toolkit.Graph.Controls/Providers/Graph.cs new file mode 100644 index 0000000..5316fff --- /dev/null +++ b/Microsoft.Toolkit.Graph.Controls/Providers/Graph.cs @@ -0,0 +1,69 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Windows.UI.Xaml; + +namespace Microsoft.Toolkit.Graph.Providers +{ + /// + /// Creates a new provider instance for the provided configuration and sets the GlobalProvider. + /// + public static class Graph + { + /// + /// Gets the Graph Config property value. + /// + /// + /// The target object to retrieve the property value from. + /// + /// + /// The value of the property on the target. + /// + public static IGraphConfig GetConfig(DependencyObject target) + { + return (IGraphConfig)target.GetValue(ConfigProperty); + } + + /// + /// Sets the GraphConfig property value. + /// + /// + /// The target object to set the value on. + /// + /// + /// The value to apply to the target property. + /// + public static void SetConfig(DependencyObject target, IGraphConfig value) + { + target.SetValue(ConfigProperty, value); + } + + /// + /// Identifies the Config dependency property. + /// + /// + /// The identifier for the Config dependency property. + /// + public static readonly DependencyProperty ConfigProperty = + DependencyProperty.RegisterAttached("Config", typeof(IGraphConfig), typeof(FrameworkElement), new PropertyMetadata(null, OnConfigChanged)); + + private static async void OnConfigChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) + { + IGraphConfig config = GetConfig(sender); + + if (config is MockConfig mockConfig) + { + ProviderManager.Instance.GlobalProvider = new MockProvider(mockConfig.SignedIn); + } + else if (config is MsalConfig msalConfig) + { + ProviderManager.Instance.GlobalProvider = await QuickCreate.CreateMsalProviderAsync(msalConfig); + } + else if (config is WindowsConfig winConfig) + { + ProviderManager.Instance.GlobalProvider = await QuickCreate.CreateWindowsProviderAsync(winConfig); + } + } + } +} diff --git a/Microsoft.Toolkit.Graph.Controls/Providers/GraphExtensions.cs b/Microsoft.Toolkit.Graph.Controls/Providers/GraphExtensions.cs deleted file mode 100644 index fd43c39..0000000 --- a/Microsoft.Toolkit.Graph.Controls/Providers/GraphExtensions.cs +++ /dev/null @@ -1,62 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System.Linq; -using Windows.UI.Xaml; - -namespace Microsoft.Toolkit.Graph.Providers -{ - /// - /// - /// - public static class GraphExtensions - { - /// - /// Gets the Graph Config property value. - /// - /// - /// - public static IGraphConfig GetGraphConfig(DependencyObject target) - { - return (IGraphConfig)target.GetValue(GraphConfigProperty); - } - - /// - /// Sets the GraphConfig property value. - /// - /// - /// - public static void SetGraphConfig(DependencyObject target, IGraphConfig value) - { - target.SetValue(GraphConfigProperty, value); - } - - /// - /// Identifies the dependency property. - /// - /// - /// The identifier for the dependency property. - /// - public static readonly DependencyProperty GraphConfigProperty = - DependencyProperty.RegisterAttached("GraphConfig", typeof(IGraphConfig), typeof(FrameworkElement), new PropertyMetadata(null, OnGraphConfigChanged)); - - private static async void OnGraphConfigChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) - { - IGraphConfig config = GetGraphConfig(sender); - - if (config is MockConfig mockConfig) - { - ProviderManager.Instance.GlobalProvider = new MockProvider(mockConfig.SignedIn); - } - else if (config is MsalConfig msalConfig) - { - ProviderManager.Instance.GlobalProvider = await QuickCreate.CreateMsalProviderAsync(msalConfig); - } - else if (config is WindowsConfig winConfig) - { - ProviderManager.Instance.GlobalProvider = await QuickCreate.CreateWindowsProviderAsync(winConfig); - } - } - } -} diff --git a/Microsoft.Toolkit.Graph.Controls/Providers/InteractiveProviderBehavior.cs b/Microsoft.Toolkit.Graph.Controls/Providers/InteractiveProviderBehavior.cs deleted file mode 100644 index 99de148..0000000 --- a/Microsoft.Toolkit.Graph.Controls/Providers/InteractiveProviderBehavior.cs +++ /dev/null @@ -1,63 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -#if DOTNET -using System; -using System.Linq; -using System.Windows; -using Microsoft.Toolkit.Graph.Providers; -#else -using System.Linq; -using Windows.System; -#endif - -#if DOTNET -namespace Microsoft.Toolkit.Wpf.Graph.Providers -#else -namespace Microsoft.Toolkit.Graph.Providers -#endif -{ - /// - /// Put in a xaml page with ClientId - /// https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/Acquiring-tokens-interactively. - /// - /// - /// - /// <Interactivity:Interaction.Behaviors> - /// <providers:InteractiveProviderBehavior ClientId = "MyClientIdGuid"/> - /// </Interactivity:Interaction.Behaviors> - /// - /// - public class InteractiveProviderBehavior : CommonProviderBehaviorBase - { - private object lock_sync = new object(); - private bool initialized = false; - - /// - protected override bool Initialize() - { - lock (lock_sync) - { - if (!initialized) - { -#if DOTNET - _ = Dispatcher.BeginInvoke(new Action(async () => - { - ProviderManager.Instance.GlobalProvider = - await QuickCreate.CreateMsalProviderAsync(ClientId, RedirectUri, Scopes.ToArray()); - }), System.Windows.Threading.DispatcherPriority.Normal); -#else - _ = DispatcherQueue.GetForCurrentThread().TryEnqueue(DispatcherQueuePriority.Normal, async () => - { - ProviderManager.Instance.GlobalProvider = - await QuickCreate.CreateMsalProviderAsync(ClientId, RedirectUri, Scopes.ToArray()); - }); -#endif - } - } - - return base.Initialize(); - } - } -} diff --git a/Microsoft.Toolkit.Graph.Controls/Providers/MockProviderBehavior.cs b/Microsoft.Toolkit.Graph.Controls/Providers/MockProviderBehavior.cs deleted file mode 100644 index 03a7ba7..0000000 --- a/Microsoft.Toolkit.Graph.Controls/Providers/MockProviderBehavior.cs +++ /dev/null @@ -1,69 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -#if DOTNET -using System; -using System.Linq; -using System.Windows; -using Microsoft.Toolkit.Graph.Providers; -#else -using System.Linq; -using Windows.UI.Xaml; -#endif - -#if DOTNET -namespace Microsoft.Toolkit.Wpf.Graph.Providers -#else -namespace Microsoft.Toolkit.Graph.Providers -#endif -{ - /// - /// Put in a xaml page with ClientId - /// https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/wiki/Acquiring-tokens-interactively. - /// - /// - /// - /// <Interactivity:Interaction.Behaviors> - /// <providers:InteractiveProviderBehavior ClientId = "MyClientIdGuid"/> - /// </Interactivity:Interaction.Behaviors> - /// - /// - public class MockProviderBehavior : CommonProviderBehaviorBase - { - private object lock_sync = new object(); - private bool initialized = false; - - /// - /// Gets or sets a value indicating whether the mock provider is signed-in upon initialization. - /// - public bool SignedIn - { - get { return (bool)GetValue(SignedInProperty); } - set { SetValue(SignedInProperty, value); } - } - - /// - /// Identifies the dependency property. - /// - /// - /// The identifier for the dependency property. - /// - public static readonly DependencyProperty SignedInProperty = - DependencyProperty.Register(nameof(SignedIn), typeof(bool), typeof(MockProviderBehavior), new PropertyMetadata(true)); - - /// - protected override bool Initialize() - { - lock (lock_sync) - { - if (!initialized) - { - ProviderManager.Instance.GlobalProvider = new MockProvider(SignedIn); - } - } - - return base.Initialize(); - } - } -} diff --git a/SampleTest/MainPage.xaml b/SampleTest/MainPage.xaml index 1990c52..df4ee83 100644 --- a/SampleTest/MainPage.xaml +++ b/SampleTest/MainPage.xaml @@ -19,15 +19,11 @@ After finishing the initial registration page, you will also need to add an additional redirect URI. Click on "Add a Redirect URI" and check the https://login.microsoftonline.com/common/oauth2/nativeclient checkbox on that page. Then click "Save". --> - - - - - + - + From b70e38612ba2f930e1abbb8a6cedca1c79066700 Mon Sep 17 00:00:00 2001 From: Shane Weaver Date: Thu, 11 Feb 2021 14:15:38 -0800 Subject: [PATCH 05/16] Moving Msal provider to separate package --- .../Providers/QuickCreate.cs | 72 --------------- ...rosoft.Toolkit.Graph.Providers.Msal.csproj | 41 +++++++++ .../MsalConfig.cs | 9 +- .../MsalProvider.cs | 83 +++++++++--------- .../Properties/AssemblyInfo.cs | 11 +++ ...rosoft.Toolkit.Graph.Providers.Msal.rd.xml | 5 ++ .../BaseProvider.cs | 14 ++- .../HttpRequestMessageExtensions.cs | 4 +- .../Graph.cs | 31 +++++-- .../IGraphConfig.cs | 0 .../Microsoft.Toolkit.Graph.Providers.csproj | 54 ++++++++++++ .../Mock}/MockConfig.cs | 2 +- .../Mock}/MockProvider.cs | 48 +++------- .../Properties/AssemblyInfo.cs | 11 +++ .../Microsoft.Toolkit.Graph.Providers.rd.xml | 5 ++ .../ScopeSet.cs | 0 .../Uwp}/WindowsConfig.cs | 7 +- .../Uwp}/WindowsProvider.cs | 16 +++- .../Microsoft.Toolkit.Graph.csproj | 6 ++ SampleTest/MainPage.xaml | 9 +- SampleTest/SampleTest.csproj | 8 ++ Windows-Toolkit-Graph-Controls.sln | 87 +++++++++++++++++++ 22 files changed, 351 insertions(+), 172 deletions(-) delete mode 100644 Microsoft.Toolkit.Graph.Controls/Providers/QuickCreate.cs create mode 100644 Microsoft.Toolkit.Graph.Providers.Msal/Microsoft.Toolkit.Graph.Providers.Msal.csproj rename {Microsoft.Toolkit.Graph.Controls/Providers => Microsoft.Toolkit.Graph.Providers.Msal}/MsalConfig.cs (84%) rename {Microsoft.Toolkit.Graph/Providers => Microsoft.Toolkit.Graph.Providers.Msal}/MsalProvider.cs (67%) create mode 100644 Microsoft.Toolkit.Graph.Providers.Msal/Properties/AssemblyInfo.cs create mode 100644 Microsoft.Toolkit.Graph.Providers.Msal/Properties/Microsoft.Toolkit.Graph.Providers.Msal.rd.xml rename {Microsoft.Toolkit.Graph/Providers => Microsoft.Toolkit.Graph.Providers}/BaseProvider.cs (79%) rename {Microsoft.Toolkit.Graph => Microsoft.Toolkit.Graph.Providers}/Extensions/HttpRequestMessageExtensions.cs (93%) rename {Microsoft.Toolkit.Graph.Controls/Providers => Microsoft.Toolkit.Graph.Providers}/Graph.cs (65%) rename {Microsoft.Toolkit.Graph.Controls/Providers => Microsoft.Toolkit.Graph.Providers}/IGraphConfig.cs (100%) create mode 100644 Microsoft.Toolkit.Graph.Providers/Microsoft.Toolkit.Graph.Providers.csproj rename {Microsoft.Toolkit.Graph.Controls/Providers => Microsoft.Toolkit.Graph.Providers/Mock}/MockConfig.cs (89%) rename {Microsoft.Toolkit.Graph/Providers => Microsoft.Toolkit.Graph.Providers/Mock}/MockProvider.cs (60%) create mode 100644 Microsoft.Toolkit.Graph.Providers/Properties/AssemblyInfo.cs create mode 100644 Microsoft.Toolkit.Graph.Providers/Properties/Microsoft.Toolkit.Graph.Providers.rd.xml rename {Microsoft.Toolkit.Graph.Controls/Providers => Microsoft.Toolkit.Graph.Providers}/ScopeSet.cs (100%) rename {Microsoft.Toolkit.Graph.Controls/Providers => Microsoft.Toolkit.Graph.Providers/Uwp}/WindowsConfig.cs (86%) rename {Microsoft.Toolkit.Graph.Controls/Providers => Microsoft.Toolkit.Graph.Providers/Uwp}/WindowsProvider.cs (95%) diff --git a/Microsoft.Toolkit.Graph.Controls/Providers/QuickCreate.cs b/Microsoft.Toolkit.Graph.Controls/Providers/QuickCreate.cs deleted file mode 100644 index 879d2b0..0000000 --- a/Microsoft.Toolkit.Graph.Controls/Providers/QuickCreate.cs +++ /dev/null @@ -1,72 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System.Linq; -using System.Reflection; -using System.Threading.Tasks; -using Microsoft.Graph.Auth; -using Microsoft.Identity.Client; -using Microsoft.Toolkit.Graph.Providers; - -#if DOTNET -namespace Microsoft.Toolkit.Wpf.Graph.Providers -#else -namespace Microsoft.Toolkit.Graph.Providers -#endif -{ - //// TODO: This should probably live in .NET Standard lib; however, Uno one needs to be at UI layer for Parent Window? - //// TODO: Need to set up XAML Islands sample to test in the new repo and make sure this works from this context. - - /// - /// Helper class to easily initialize provider from just ClientId. - /// - public static class QuickCreate - { - /// - /// Easily creates a from a config object. - /// - /// Msal configuraiton object. - /// New reference. - public static Task CreateMsalProviderAsync(MsalConfig config) - { - return CreateMsalProviderAsync(config.ClientId, config.RedirectUri, config.Scopes.ToArray()); - } - - /// - /// Easily creates a from a ClientId. - /// - /// - /// - /// ProviderManager.Instance.GlobalProvider = await QuickCreate.CreateMsalProviderAsync("MyClientId"); - /// - /// - /// Registered ClientId. - /// RedirectUri for auth response. - /// List of Scopes to initially request. - /// New reference. - public static async Task CreateMsalProviderAsync(string clientid, string redirectUri = "https://login.microsoftonline.com/common/oauth2/nativeclient", string[] scopes = null) - { - var client = PublicClientApplicationBuilder.Create(clientid) - .WithAuthority(AzureCloudInstance.AzurePublic, AadAuthorityAudience.AzureAdAndPersonalMicrosoftAccount) - .WithRedirectUri(redirectUri) - .WithClientName(ProviderManager.ClientName) - .WithClientVersion(Assembly.GetExecutingAssembly().GetName().Version.ToString()) - .Build(); - - var provider = new InteractiveAuthenticationProvider(client, scopes); - - return await MsalProvider.CreateAsync(client, provider); - } - - /// - /// Easily creates a from a config object. - /// - /// Windows configuration object. - /// New reference. - public static async Task CreateWindowsProviderAsync(WindowsConfig config) - { - return await WindowsProvider.CreateAsync(config.ClientId, config.Scopes.ToArray()); - } - } -} diff --git a/Microsoft.Toolkit.Graph.Providers.Msal/Microsoft.Toolkit.Graph.Providers.Msal.csproj b/Microsoft.Toolkit.Graph.Providers.Msal/Microsoft.Toolkit.Graph.Providers.Msal.csproj new file mode 100644 index 0000000..7a997ca --- /dev/null +++ b/Microsoft.Toolkit.Graph.Providers.Msal/Microsoft.Toolkit.Graph.Providers.Msal.csproj @@ -0,0 +1,41 @@ + + + + uap10.0.17763 + Windows Community Toolkit Msal Graph Provider + Microsoft.Toolkit.Graph.Providers.Msal + + This library provides... It is part of the Windows Community Toolkit. + + Classes: + - MsalProvider: + - MsalConfig: + + UWP Toolkit Windows Controls MSAL Microsoft Graph AadLogin Login + false + true + 8.0 + Debug;Release;CI + AnyCPU;ARM;ARM64;x64;x86 + + + + + + + + + + + + + + + + + + + + + + diff --git a/Microsoft.Toolkit.Graph.Controls/Providers/MsalConfig.cs b/Microsoft.Toolkit.Graph.Providers.Msal/MsalConfig.cs similarity index 84% rename from Microsoft.Toolkit.Graph.Controls/Providers/MsalConfig.cs rename to Microsoft.Toolkit.Graph.Providers.Msal/MsalConfig.cs index 713ef50..cd763a9 100644 --- a/Microsoft.Toolkit.Graph.Controls/Providers/MsalConfig.cs +++ b/Microsoft.Toolkit.Graph.Providers.Msal/MsalConfig.cs @@ -2,13 +2,18 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Microsoft.Toolkit.Graph.Providers +namespace Microsoft.Toolkit.Graph.Providers.Msal { /// - /// + /// Configuration values for initializing the MsalProvider. /// public class MsalConfig : IGraphConfig { + static MsalConfig() + { + Graph.RegisterConfig(typeof(MsalConfig), (c) => MsalProvider.Create(c as MsalConfig)); + } + /// /// Gets or sets the Client ID (the unique application (client) ID assigned to your app by Azure AD when the app was registered). /// diff --git a/Microsoft.Toolkit.Graph/Providers/MsalProvider.cs b/Microsoft.Toolkit.Graph.Providers.Msal/MsalProvider.cs similarity index 67% rename from Microsoft.Toolkit.Graph/Providers/MsalProvider.cs rename to Microsoft.Toolkit.Graph.Providers.Msal/MsalProvider.cs index 98a2e61..4110edd 100644 --- a/Microsoft.Toolkit.Graph/Providers/MsalProvider.cs +++ b/Microsoft.Toolkit.Graph.Providers.Msal/MsalProvider.cs @@ -3,23 +3,20 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Reflection; using System.Threading.Tasks; using Microsoft.Graph; +using Microsoft.Graph.Auth; using Microsoft.Identity.Client; -using Microsoft.Toolkit.Graph.Extensions; -namespace Microsoft.Toolkit.Graph.Providers +namespace Microsoft.Toolkit.Graph.Providers.Msal { - //// TODO: Move some of this to a simple base-class for non-MSAL parts related to Provider only and properties? - /// /// MSAL.NET provider helper for tracking authentication state using an class. /// - public class MsalProvider : IProvider + public class MsalProvider : BaseProvider { /// /// Gets or sets the MSAL.NET Client used to authenticate the user. @@ -31,65 +28,67 @@ public class MsalProvider : IProvider /// protected IAuthenticationProvider Provider { get; set; } - private ProviderState _state = ProviderState.Loading; - - /// - public ProviderState State + /// + /// Initializes a new instance of the class. . + /// + private MsalProvider() { - get - { - return _state; - } - - private set - { - var current = _state; - _state = value; - - StateChanged?.Invoke(this, new ProviderStateChangedEventArgs(current, _state)); - } } - /// - public GraphServiceClient Graph { get; private set; } - - /// - public event EventHandler StateChanged; - /// - /// Initializes a new instance of the class. . + /// Easily creates a from a config object. /// - private MsalProvider() + /// + /// + public static MsalProvider Create(MsalConfig config) { + return Create(config.ClientId, config.RedirectUri, config.Scopes.ToArray()); } /// - /// Initializes a new instance of the class. + /// Easily creates a from a ClientId. /// - /// Existing instance. - /// Existing instance. - /// A returning a instance. - public static async Task CreateAsync(IPublicClientApplication client, IAuthenticationProvider provider) + /// + /// + /// ProviderManager.Instance.GlobalProvider = await QuickCreate.CreateMsalProviderAsync("MyClientId"); + /// + /// + /// Registered ClientId. + /// RedirectUri for auth response. + /// List of Scopes to initially request. + /// New reference. + public static MsalProvider Create(string clientid, string redirectUri = "https://login.microsoftonline.com/common/oauth2/nativeclient", string[] scopes = null) { //// TODO: Check all config provided + var client = PublicClientApplicationBuilder.Create(clientid) + .WithAuthority(AzureCloudInstance.AzurePublic, AadAuthorityAudience.AzureAdAndPersonalMicrosoftAccount) + .WithRedirectUri(redirectUri) + .WithClientName(ProviderManager.ClientName) + .WithClientVersion(Assembly.GetExecutingAssembly().GetName().Version.ToString()) + .Build(); + + if (scopes == null) + { + scopes = new string[] { string.Empty }; + } + var msal = new MsalProvider { Client = client, - Provider = provider, + Provider = new InteractiveAuthenticationProvider(client, scopes), }; - msal.Graph = new GraphServiceClient(msal); - await msal.TrySilentSignInAsync(); + msal.TrySilentSignInAsync(); return msal; } /// - public async Task AuthenticateRequestAsync(HttpRequestMessage request) + public override async Task AuthenticateRequestAsync(HttpRequestMessage request) { - request.AddSdkVersion(); + AddSdkVersion(request); try { @@ -159,14 +158,14 @@ public async Task TrySilentSignInAsync() } /// - public async Task LoginAsync() + public override async Task LoginAsync() { // Force fake request to start auth process await AuthenticateRequestAsync(new System.Net.Http.HttpRequestMessage()); } /// - public async Task LogoutAsync() + public override async Task LogoutAsync() { // Forcibly remove each user. foreach (var user in await Client.GetAccountsAsync()) diff --git a/Microsoft.Toolkit.Graph.Providers.Msal/Properties/AssemblyInfo.cs b/Microsoft.Toolkit.Graph.Providers.Msal/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c244792 --- /dev/null +++ b/Microsoft.Toolkit.Graph.Providers.Msal/Properties/AssemblyInfo.cs @@ -0,0 +1,11 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Resources; +using System.Runtime.CompilerServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: NeutralResourcesLanguage("en-US")] \ No newline at end of file diff --git a/Microsoft.Toolkit.Graph.Providers.Msal/Properties/Microsoft.Toolkit.Graph.Providers.Msal.rd.xml b/Microsoft.Toolkit.Graph.Providers.Msal/Properties/Microsoft.Toolkit.Graph.Providers.Msal.rd.xml new file mode 100644 index 0000000..195d8f6 --- /dev/null +++ b/Microsoft.Toolkit.Graph.Providers.Msal/Properties/Microsoft.Toolkit.Graph.Providers.Msal.rd.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/Microsoft.Toolkit.Graph/Providers/BaseProvider.cs b/Microsoft.Toolkit.Graph.Providers/BaseProvider.cs similarity index 79% rename from Microsoft.Toolkit.Graph/Providers/BaseProvider.cs rename to Microsoft.Toolkit.Graph.Providers/BaseProvider.cs index c684299..4c5d7f7 100644 --- a/Microsoft.Toolkit.Graph/Providers/BaseProvider.cs +++ b/Microsoft.Toolkit.Graph.Providers/BaseProvider.cs @@ -6,6 +6,7 @@ using System.Net.Http; using System.Threading.Tasks; using Microsoft.Graph; +using Microsoft.Toolkit.Graph.Providers.Extensions; namespace Microsoft.Toolkit.Graph.Providers { @@ -40,7 +41,7 @@ protected set /// /// Gets or sets the service client instance for making Graph calls. /// - public GraphServiceClient Graph { get; protected set; } + public virtual GraphServiceClient Graph { get; protected set; } /// /// Initializes a new instance of the class. @@ -58,5 +59,16 @@ public BaseProvider() /// public abstract Task AuthenticateRequestAsync(HttpRequestMessage request); + + /// + /// Append the Sdk version to the request headers. + /// + /// + /// The request to append the header to. + /// + protected void AddSdkVersion(HttpRequestMessage request) + { + request.AddSdkVersion(); + } } } diff --git a/Microsoft.Toolkit.Graph/Extensions/HttpRequestMessageExtensions.cs b/Microsoft.Toolkit.Graph.Providers/Extensions/HttpRequestMessageExtensions.cs similarity index 93% rename from Microsoft.Toolkit.Graph/Extensions/HttpRequestMessageExtensions.cs rename to Microsoft.Toolkit.Graph.Providers/Extensions/HttpRequestMessageExtensions.cs index 9d75abf..5b5e666 100644 --- a/Microsoft.Toolkit.Graph/Extensions/HttpRequestMessageExtensions.cs +++ b/Microsoft.Toolkit.Graph.Providers/Extensions/HttpRequestMessageExtensions.cs @@ -11,12 +11,12 @@ using System.Text; using System.Threading.Tasks; -namespace Microsoft.Toolkit.Graph.Extensions +namespace Microsoft.Toolkit.Graph.Providers.Extensions { /// /// Helpers for Graph related HTTP Headers. /// - internal static class HttpRequestMessageExtensions + public static class HttpRequestMessageExtensions { private const string SdkVersion = "SdkVersion"; private const string LibraryName = "wct"; diff --git a/Microsoft.Toolkit.Graph.Controls/Providers/Graph.cs b/Microsoft.Toolkit.Graph.Providers/Graph.cs similarity index 65% rename from Microsoft.Toolkit.Graph.Controls/Providers/Graph.cs rename to Microsoft.Toolkit.Graph.Providers/Graph.cs index 5316fff..f73979e 100644 --- a/Microsoft.Toolkit.Graph.Controls/Providers/Graph.cs +++ b/Microsoft.Toolkit.Graph.Providers/Graph.cs @@ -2,6 +2,10 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Microsoft.Graph; +using Microsoft.Toolkit.Graph.Providers.Mock; +using System; +using System.Collections.Generic; using Windows.UI.Xaml; namespace Microsoft.Toolkit.Graph.Providers @@ -48,21 +52,34 @@ public static void SetConfig(DependencyObject target, IGraphConfig value) public static readonly DependencyProperty ConfigProperty = DependencyProperty.RegisterAttached("Config", typeof(IGraphConfig), typeof(FrameworkElement), new PropertyMetadata(null, OnConfigChanged)); - private static async void OnConfigChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) + private static void OnConfigChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { IGraphConfig config = GetConfig(sender); - if (config is MockConfig mockConfig) + Type configType = config.GetType(); + if (_providers.ContainsKey(configType)) { - ProviderManager.Instance.GlobalProvider = new MockProvider(mockConfig.SignedIn); + var providerFactory = _providers[configType]; + ProviderManager.Instance.GlobalProvider = providerFactory.Invoke(config); } - else if (config is MsalConfig msalConfig) + else if (config is MockConfig mockConfig) { - ProviderManager.Instance.GlobalProvider = await QuickCreate.CreateMsalProviderAsync(msalConfig); + ProviderManager.Instance.GlobalProvider = new MockProvider(mockConfig); } - else if (config is WindowsConfig winConfig) + } + + private static Dictionary> _providers = new Dictionary>(); + + /// + /// + /// + /// + /// + public static void RegisterConfig(Type configType, Func providerFactory) + { + if (!_providers.ContainsKey(configType)) { - ProviderManager.Instance.GlobalProvider = await QuickCreate.CreateWindowsProviderAsync(winConfig); + _providers.Add(configType, providerFactory); } } } diff --git a/Microsoft.Toolkit.Graph.Controls/Providers/IGraphConfig.cs b/Microsoft.Toolkit.Graph.Providers/IGraphConfig.cs similarity index 100% rename from Microsoft.Toolkit.Graph.Controls/Providers/IGraphConfig.cs rename to Microsoft.Toolkit.Graph.Providers/IGraphConfig.cs diff --git a/Microsoft.Toolkit.Graph.Providers/Microsoft.Toolkit.Graph.Providers.csproj b/Microsoft.Toolkit.Graph.Providers/Microsoft.Toolkit.Graph.Providers.csproj new file mode 100644 index 0000000..ebd513a --- /dev/null +++ b/Microsoft.Toolkit.Graph.Providers/Microsoft.Toolkit.Graph.Providers.csproj @@ -0,0 +1,54 @@ + + + + uap10.0.17763 + Windows Community Toolkit Graph Controls + Microsoft.Toolkit.Graph.Controls + + This library provides base constructs for building Microsoft Graph XAML providers. It is part of the Windows Community Toolkit. + + Classes: + - BaseProvider: + - MockProvider: + - MockConfig: + - ScopeSet: + + UWP Toolkit Windows Controls MSAL Microsoft Graph AadLogin ProfileCard Person PeoplePicker Login + false + true + 8.0 + Debug;Release;CI + AnyCPU;ARM;ARM64;x64;x86 + + + + + + + + + + + + + + + + + + + + MSBuild:Compile + + + + + + + + + + + + + diff --git a/Microsoft.Toolkit.Graph.Controls/Providers/MockConfig.cs b/Microsoft.Toolkit.Graph.Providers/Mock/MockConfig.cs similarity index 89% rename from Microsoft.Toolkit.Graph.Controls/Providers/MockConfig.cs rename to Microsoft.Toolkit.Graph.Providers/Mock/MockConfig.cs index 4877b34..24fa211 100644 --- a/Microsoft.Toolkit.Graph.Controls/Providers/MockConfig.cs +++ b/Microsoft.Toolkit.Graph.Providers/Mock/MockConfig.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Microsoft.Toolkit.Graph.Providers +namespace Microsoft.Toolkit.Graph.Providers.Mock { /// /// diff --git a/Microsoft.Toolkit.Graph/Providers/MockProvider.cs b/Microsoft.Toolkit.Graph.Providers/Mock/MockProvider.cs similarity index 60% rename from Microsoft.Toolkit.Graph/Providers/MockProvider.cs rename to Microsoft.Toolkit.Graph.Providers/Mock/MockProvider.cs index a26badd..9ebc76c 100644 --- a/Microsoft.Toolkit.Graph/Providers/MockProvider.cs +++ b/Microsoft.Toolkit.Graph.Providers/Mock/MockProvider.cs @@ -3,47 +3,22 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections.Generic; -using System.Linq; using System.Net.Http; -using System.Net.Http.Headers; -using System.Reflection; -using System.Text; using System.Threading.Tasks; -using System.Web; using Microsoft.Graph; -using Microsoft.Toolkit.Graph.Extensions; +using Microsoft.Toolkit.Graph.Providers.Extensions; -namespace Microsoft.Toolkit.Graph.Providers +namespace Microsoft.Toolkit.Graph.Providers.Mock { /// /// Provider to connect to the example data set for Microsoft Graph. Useful for prototyping and samples. /// - public class MockProvider : IProvider + public class MockProvider : BaseProvider { private const string GRAPH_PROXY_URL = "https://proxy.apisandbox.msdn.microsoft.com/svc?url="; - private ProviderState _state = ProviderState.Loading; - /// - public ProviderState State - { - get - { - return _state; - } - - private set - { - var current = _state; - _state = value; - - StateChanged?.Invoke(this, new ProviderStateChangedEventArgs(current, _state)); - } - } - - /// - public GraphServiceClient Graph => new GraphServiceClient( + public override GraphServiceClient Graph => new GraphServiceClient( new DelegateAuthenticationProvider((requestMessage) => { var requestUri = requestMessage.RequestUri.ToString(); @@ -54,16 +29,13 @@ private set return this.AuthenticateRequestAsync(requestMessage); })); - /// - public event EventHandler StateChanged; - /// /// Initializes a new instance of the class. /// - /// Whether the default state should be signedIn, defaults to true. - public MockProvider(bool signedIn = true) + /// Configuration for the MockProvider. + public MockProvider(MockConfig config = null) { - if (signedIn) + if (config == null || config.SignedIn) { State = ProviderState.SignedIn; } @@ -74,7 +46,7 @@ public MockProvider(bool signedIn = true) } /// - public Task AuthenticateRequestAsync(HttpRequestMessage request) + public override Task AuthenticateRequestAsync(HttpRequestMessage request) { request.AddSdkVersion(); @@ -84,7 +56,7 @@ public Task AuthenticateRequestAsync(HttpRequestMessage request) } /// - public async Task LoginAsync() + public override async Task LoginAsync() { State = ProviderState.Loading; await Task.Delay(3000); @@ -92,7 +64,7 @@ public async Task LoginAsync() } /// - public async Task LogoutAsync() + public override async Task LogoutAsync() { State = ProviderState.Loading; await Task.Delay(3000); diff --git a/Microsoft.Toolkit.Graph.Providers/Properties/AssemblyInfo.cs b/Microsoft.Toolkit.Graph.Providers/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c244792 --- /dev/null +++ b/Microsoft.Toolkit.Graph.Providers/Properties/AssemblyInfo.cs @@ -0,0 +1,11 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Resources; +using System.Runtime.CompilerServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: NeutralResourcesLanguage("en-US")] \ No newline at end of file diff --git a/Microsoft.Toolkit.Graph.Providers/Properties/Microsoft.Toolkit.Graph.Providers.rd.xml b/Microsoft.Toolkit.Graph.Providers/Properties/Microsoft.Toolkit.Graph.Providers.rd.xml new file mode 100644 index 0000000..b4f2d7f --- /dev/null +++ b/Microsoft.Toolkit.Graph.Providers/Properties/Microsoft.Toolkit.Graph.Providers.rd.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/Microsoft.Toolkit.Graph.Controls/Providers/ScopeSet.cs b/Microsoft.Toolkit.Graph.Providers/ScopeSet.cs similarity index 100% rename from Microsoft.Toolkit.Graph.Controls/Providers/ScopeSet.cs rename to Microsoft.Toolkit.Graph.Providers/ScopeSet.cs diff --git a/Microsoft.Toolkit.Graph.Controls/Providers/WindowsConfig.cs b/Microsoft.Toolkit.Graph.Providers/Uwp/WindowsConfig.cs similarity index 86% rename from Microsoft.Toolkit.Graph.Controls/Providers/WindowsConfig.cs rename to Microsoft.Toolkit.Graph.Providers/Uwp/WindowsConfig.cs index dc4d67a..1c8b01b 100644 --- a/Microsoft.Toolkit.Graph.Controls/Providers/WindowsConfig.cs +++ b/Microsoft.Toolkit.Graph.Providers/Uwp/WindowsConfig.cs @@ -2,13 +2,18 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Microsoft.Toolkit.Graph.Providers +namespace Microsoft.Toolkit.Graph.Providers.Uwp { /// /// Basic configuration for talking to the Graph. /// public class WindowsConfig : IGraphConfig { + static WindowsConfig() + { + Graph.RegisterConfig(typeof(WindowsConfig), (c) => WindowsProvider.Create(c as WindowsConfig)); + } + /// /// Gets or sets the Client ID (the unique application (client) ID assigned to your app by Azure AD when the app was registered). /// diff --git a/Microsoft.Toolkit.Graph.Controls/Providers/WindowsProvider.cs b/Microsoft.Toolkit.Graph.Providers/Uwp/WindowsProvider.cs similarity index 95% rename from Microsoft.Toolkit.Graph.Controls/Providers/WindowsProvider.cs rename to Microsoft.Toolkit.Graph.Providers/Uwp/WindowsProvider.cs index aaa0f26..ee13e04 100644 --- a/Microsoft.Toolkit.Graph.Controls/Providers/WindowsProvider.cs +++ b/Microsoft.Toolkit.Graph.Providers/Uwp/WindowsProvider.cs @@ -13,7 +13,7 @@ using Windows.Security.Authentication.Web.Core; using Windows.UI.ApplicationSettings; -namespace Microsoft.Toolkit.Graph.Providers +namespace Microsoft.Toolkit.Graph.Providers.Uwp { /// /// A provider for leveraging Windows system authentication. @@ -55,19 +55,29 @@ public AuthenticatedUser(Windows.Security.Credentials.PasswordCredential tokenCr private string[] _scopes; private string _clientId; + /// + /// + /// + /// + /// + public static WindowsProvider Create(WindowsConfig config) + { + return Create(config.ClientId, config.Scopes.ToArray()); + } + /// /// Creates a new instance of the WindowsProvider and attempts to sign in silently. /// /// /// /// A new instance of a WindowsProvider. - public static async Task CreateAsync(string clientId, string[] scopes) + public static WindowsProvider Create(string clientId, string[] scopes) { var provider = new WindowsProvider(clientId, scopes); provider.Graph = new GraphServiceClient(provider); - await provider.TrySilentSignInAsync(); + provider.TrySilentSignInAsync(); return provider; } diff --git a/Microsoft.Toolkit.Graph/Microsoft.Toolkit.Graph.csproj b/Microsoft.Toolkit.Graph/Microsoft.Toolkit.Graph.csproj index b29ab1d..6312d24 100644 --- a/Microsoft.Toolkit.Graph/Microsoft.Toolkit.Graph.csproj +++ b/Microsoft.Toolkit.Graph/Microsoft.Toolkit.Graph.csproj @@ -20,6 +20,12 @@ $(DefineConstants);WINRT + + + + + + diff --git a/SampleTest/MainPage.xaml b/SampleTest/MainPage.xaml index df4ee83..384a726 100644 --- a/SampleTest/MainPage.xaml +++ b/SampleTest/MainPage.xaml @@ -8,6 +8,9 @@ xmlns:local="using:SampleTest" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:providers="using:Microsoft.Toolkit.Graph.Providers" + xmlns:msal="using:Microsoft.Toolkit.Graph.Providers.Msal" + xmlns:uwp="using:Microsoft.Toolkit.Graph.Providers.Uwp" + xmlns:mock="using:Microsoft.Toolkit.Graph.Providers.Mock" xmlns:wgt="using:Microsoft.Toolkit.Graph.Controls" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" mc:Ignorable="d"> @@ -20,9 +23,9 @@ Click on "Add a Redirect URI" and check the https://login.microsoftonline.com/common/oauth2/nativeclient checkbox on that page. Then click "Save". --> - - - + + + diff --git a/SampleTest/SampleTest.csproj b/SampleTest/SampleTest.csproj index 430a172..2d846ea 100644 --- a/SampleTest/SampleTest.csproj +++ b/SampleTest/SampleTest.csproj @@ -161,6 +161,14 @@ {42252ee8-7e68-428f-972b-6d2dd3aa12cc} Microsoft.Toolkit.Graph.Controls + + {36d0b51d-111b-4fc3-84e0-ce085172b9cc} + Microsoft.Toolkit.Graph.Providers.Msal + + + {10dff17a-183c-4112-9b94-b9e2aac5e4c8} + Microsoft.Toolkit.Graph.Providers + {B2246169-0CD8-473C-AFF6-172310E2C3F6} Microsoft.Toolkit.Graph diff --git a/Windows-Toolkit-Graph-Controls.sln b/Windows-Toolkit-Graph-Controls.sln index 3ee888b..833fd5c 100644 --- a/Windows-Toolkit-Graph-Controls.sln +++ b/Windows-Toolkit-Graph-Controls.sln @@ -38,6 +38,13 @@ Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "WPF-Packaged-App", "Samples EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Toolkit.Wpf.Graph.Providers", "Microsoft.Toolkit.Wpf.Graph.Providers\Microsoft.Toolkit.Wpf.Graph.Providers.csproj", "{8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Toolkit.Graph.Providers", "Microsoft.Toolkit.Graph.Providers\Microsoft.Toolkit.Graph.Providers.csproj", "{10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Toolkit.Graph.Providers.Msal", "Microsoft.Toolkit.Graph.Providers.Msal\Microsoft.Toolkit.Graph.Providers.Msal.csproj", "{36D0B51D-111B-4FC3-84E0-CE085172B9CC}" + ProjectSection(ProjectDependencies) = postProject + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8} = {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution CI|Any CPU = CI|Any CPU @@ -351,6 +358,86 @@ Global {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Release|x64.Build.0 = Release|Any CPU {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Release|x86.ActiveCfg = Release|Any CPU {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Release|x86.Build.0 = Release|Any CPU + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.CI|Any CPU.ActiveCfg = CI|Any CPU + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.CI|Any CPU.Build.0 = CI|Any CPU + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.CI|ARM.ActiveCfg = CI|ARM + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.CI|ARM.Build.0 = CI|ARM + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.CI|ARM64.ActiveCfg = CI|ARM64 + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.CI|ARM64.Build.0 = CI|ARM64 + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.CI|x64.ActiveCfg = CI|x64 + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.CI|x64.Build.0 = CI|x64 + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.CI|x86.ActiveCfg = CI|x86 + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.CI|x86.Build.0 = CI|x86 + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Debug|ARM.ActiveCfg = Debug|ARM + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Debug|ARM.Build.0 = Debug|ARM + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Debug|ARM64.Build.0 = Debug|ARM64 + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Debug|x64.ActiveCfg = Debug|x64 + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Debug|x64.Build.0 = Debug|x64 + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Debug|x86.ActiveCfg = Debug|x86 + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Debug|x86.Build.0 = Debug|x86 + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Native|Any CPU.ActiveCfg = Debug|Any CPU + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Native|Any CPU.Build.0 = Debug|Any CPU + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Native|ARM.ActiveCfg = Debug|ARM + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Native|ARM.Build.0 = Debug|ARM + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Native|ARM64.ActiveCfg = Debug|ARM64 + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Native|ARM64.Build.0 = Debug|ARM64 + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Native|x64.ActiveCfg = Debug|x64 + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Native|x64.Build.0 = Debug|x64 + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Native|x86.ActiveCfg = Debug|x86 + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Native|x86.Build.0 = Debug|x86 + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Release|Any CPU.Build.0 = Release|Any CPU + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Release|ARM.ActiveCfg = Release|ARM + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Release|ARM.Build.0 = Release|ARM + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Release|ARM64.ActiveCfg = Release|ARM64 + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Release|ARM64.Build.0 = Release|ARM64 + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Release|x64.ActiveCfg = Release|x64 + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Release|x64.Build.0 = Release|x64 + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Release|x86.ActiveCfg = Release|x86 + {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.Release|x86.Build.0 = Release|x86 + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.CI|Any CPU.ActiveCfg = CI|Any CPU + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.CI|Any CPU.Build.0 = CI|Any CPU + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.CI|ARM.ActiveCfg = CI|ARM + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.CI|ARM.Build.0 = CI|ARM + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.CI|ARM64.ActiveCfg = CI|ARM64 + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.CI|ARM64.Build.0 = CI|ARM64 + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.CI|x64.ActiveCfg = CI|x64 + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.CI|x64.Build.0 = CI|x64 + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.CI|x86.ActiveCfg = CI|x86 + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.CI|x86.Build.0 = CI|x86 + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Debug|ARM.ActiveCfg = Debug|ARM + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Debug|ARM.Build.0 = Debug|ARM + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Debug|ARM64.Build.0 = Debug|ARM64 + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Debug|x64.ActiveCfg = Debug|x64 + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Debug|x64.Build.0 = Debug|x64 + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Debug|x86.ActiveCfg = Debug|x86 + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Debug|x86.Build.0 = Debug|x86 + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Native|Any CPU.ActiveCfg = Debug|Any CPU + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Native|Any CPU.Build.0 = Debug|Any CPU + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Native|ARM.ActiveCfg = Debug|ARM + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Native|ARM.Build.0 = Debug|ARM + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Native|ARM64.ActiveCfg = Debug|ARM64 + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Native|ARM64.Build.0 = Debug|ARM64 + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Native|x64.ActiveCfg = Debug|x64 + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Native|x64.Build.0 = Debug|x64 + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Native|x86.ActiveCfg = Debug|x86 + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Native|x86.Build.0 = Debug|x86 + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Release|Any CPU.Build.0 = Release|Any CPU + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Release|ARM.ActiveCfg = Release|ARM + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Release|ARM.Build.0 = Release|ARM + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Release|ARM64.ActiveCfg = Release|ARM64 + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Release|ARM64.Build.0 = Release|ARM64 + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Release|x64.ActiveCfg = Release|x64 + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Release|x64.Build.0 = Release|x64 + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Release|x86.ActiveCfg = Release|x86 + {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 69ed7e9486954b582906db90cce100b819ac3a5f Mon Sep 17 00:00:00 2001 From: Shane Weaver Date: Thu, 11 Feb 2021 15:03:30 -0800 Subject: [PATCH 06/16] Adjusted namespaces and added some comments --- Microsoft.Toolkit.Graph.Providers/Graph.cs | 19 ++++++++++++++----- .../Microsoft.Toolkit.Graph.Providers.csproj | 14 ++------------ .../{Mock => }/MockConfig.cs | 2 +- .../{Mock => }/MockProvider.cs | 2 +- SampleTest/MainPage.xaml | 3 +-- 5 files changed, 19 insertions(+), 21 deletions(-) rename Microsoft.Toolkit.Graph.Providers/{Mock => }/MockConfig.cs (89%) rename Microsoft.Toolkit.Graph.Providers/{Mock => }/MockProvider.cs (98%) diff --git a/Microsoft.Toolkit.Graph.Providers/Graph.cs b/Microsoft.Toolkit.Graph.Providers/Graph.cs index f73979e..4f8d1e0 100644 --- a/Microsoft.Toolkit.Graph.Providers/Graph.cs +++ b/Microsoft.Toolkit.Graph.Providers/Graph.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.Graph; -using Microsoft.Toolkit.Graph.Providers.Mock; using System; using System.Collections.Generic; using Windows.UI.Xaml; @@ -71,10 +69,21 @@ private static void OnConfigChanged(DependencyObject sender, DependencyPropertyC private static Dictionary> _providers = new Dictionary>(); /// - /// + /// Register a provider to be available for declaration in XAML using the ConfigProperty. + /// Use in the static constructor of an IGraphConfig implementation. /// - /// - /// + /// + /// static MsalConfig() + /// { + /// Graph.RegisterConfig(typeof(MsalConfig), (c) => MsalProvider.Create(c as MsalConfig)); + /// }. + /// + /// + /// The Type of the IGraphConfig implementation associated with provider. + /// + /// + /// A factory function for creating a new instance of the IProvider implementation. + /// public static void RegisterConfig(Type configType, Func providerFactory) { if (!_providers.ContainsKey(configType)) diff --git a/Microsoft.Toolkit.Graph.Providers/Microsoft.Toolkit.Graph.Providers.csproj b/Microsoft.Toolkit.Graph.Providers/Microsoft.Toolkit.Graph.Providers.csproj index ebd513a..226cd6d 100644 --- a/Microsoft.Toolkit.Graph.Providers/Microsoft.Toolkit.Graph.Providers.csproj +++ b/Microsoft.Toolkit.Graph.Providers/Microsoft.Toolkit.Graph.Providers.csproj @@ -2,7 +2,7 @@ uap10.0.17763 - Windows Community Toolkit Graph Controls + Windows Community Toolkit Graph Providers Microsoft.Toolkit.Graph.Controls This library provides base constructs for building Microsoft Graph XAML providers. It is part of the Windows Community Toolkit. @@ -13,7 +13,7 @@ - MockConfig: - ScopeSet: - UWP Toolkit Windows Controls MSAL Microsoft Graph AadLogin ProfileCard Person PeoplePicker Login + UWP Toolkit Windows Providers MSAL Microsoft Graph AadLogin Login false true 8.0 @@ -21,10 +21,6 @@ AnyCPU;ARM;ARM64;x64;x86 - - - - @@ -35,12 +31,6 @@ - - - - MSBuild:Compile - - diff --git a/Microsoft.Toolkit.Graph.Providers/Mock/MockConfig.cs b/Microsoft.Toolkit.Graph.Providers/MockConfig.cs similarity index 89% rename from Microsoft.Toolkit.Graph.Providers/Mock/MockConfig.cs rename to Microsoft.Toolkit.Graph.Providers/MockConfig.cs index 24fa211..4877b34 100644 --- a/Microsoft.Toolkit.Graph.Providers/Mock/MockConfig.cs +++ b/Microsoft.Toolkit.Graph.Providers/MockConfig.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -namespace Microsoft.Toolkit.Graph.Providers.Mock +namespace Microsoft.Toolkit.Graph.Providers { /// /// diff --git a/Microsoft.Toolkit.Graph.Providers/Mock/MockProvider.cs b/Microsoft.Toolkit.Graph.Providers/MockProvider.cs similarity index 98% rename from Microsoft.Toolkit.Graph.Providers/Mock/MockProvider.cs rename to Microsoft.Toolkit.Graph.Providers/MockProvider.cs index 9ebc76c..beec22e 100644 --- a/Microsoft.Toolkit.Graph.Providers/Mock/MockProvider.cs +++ b/Microsoft.Toolkit.Graph.Providers/MockProvider.cs @@ -8,7 +8,7 @@ using Microsoft.Graph; using Microsoft.Toolkit.Graph.Providers.Extensions; -namespace Microsoft.Toolkit.Graph.Providers.Mock +namespace Microsoft.Toolkit.Graph.Providers { /// /// Provider to connect to the example data set for Microsoft Graph. Useful for prototyping and samples. diff --git a/SampleTest/MainPage.xaml b/SampleTest/MainPage.xaml index 384a726..f3a78c5 100644 --- a/SampleTest/MainPage.xaml +++ b/SampleTest/MainPage.xaml @@ -10,7 +10,6 @@ xmlns:providers="using:Microsoft.Toolkit.Graph.Providers" xmlns:msal="using:Microsoft.Toolkit.Graph.Providers.Msal" xmlns:uwp="using:Microsoft.Toolkit.Graph.Providers.Uwp" - xmlns:mock="using:Microsoft.Toolkit.Graph.Providers.Mock" xmlns:wgt="using:Microsoft.Toolkit.Graph.Controls" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" mc:Ignorable="d"> @@ -25,7 +24,7 @@ - + From 1aa3b68991f44a46f042c59c8995359bf30dd160 Mon Sep 17 00:00:00 2001 From: Shane Weaver Date: Thu, 11 Feb 2021 15:12:13 -0800 Subject: [PATCH 07/16] Moving WindowsProvider to Uwp package --- ...crosoft.Toolkit.Graph.Providers.Uwp.csproj | 41 ++++++++++++++++++ .../Properties/AssemblyInfo.cs | 11 +++++ ...crosoft.Toolkit.Graph.Providers.Uwp.rd.xml | 5 +++ .../WindowsConfig.cs | 0 .../WindowsProvider.cs | 0 SampleTest/SampleTest.csproj | 4 ++ Windows-Toolkit-Graph-Controls.sln | 42 +++++++++++++++++++ 7 files changed, 103 insertions(+) create mode 100644 Microsoft.Toolkit.Graph.Providers.Uwp/Microsoft.Toolkit.Graph.Providers.Uwp.csproj create mode 100644 Microsoft.Toolkit.Graph.Providers.Uwp/Properties/AssemblyInfo.cs create mode 100644 Microsoft.Toolkit.Graph.Providers.Uwp/Properties/Microsoft.Toolkit.Graph.Providers.Uwp.rd.xml rename {Microsoft.Toolkit.Graph.Providers/Uwp => Microsoft.Toolkit.Graph.Providers.Uwp}/WindowsConfig.cs (100%) rename {Microsoft.Toolkit.Graph.Providers/Uwp => Microsoft.Toolkit.Graph.Providers.Uwp}/WindowsProvider.cs (100%) diff --git a/Microsoft.Toolkit.Graph.Providers.Uwp/Microsoft.Toolkit.Graph.Providers.Uwp.csproj b/Microsoft.Toolkit.Graph.Providers.Uwp/Microsoft.Toolkit.Graph.Providers.Uwp.csproj new file mode 100644 index 0000000..bda6318 --- /dev/null +++ b/Microsoft.Toolkit.Graph.Providers.Uwp/Microsoft.Toolkit.Graph.Providers.Uwp.csproj @@ -0,0 +1,41 @@ + + + + uap10.0.17763 + Windows Community Toolkit Uwp Graph Provider + Microsoft.Toolkit.Graph.Providers.Msal + + This library provides an IProvider implenetation that authenticates using the native Windows dialoges. It is part of the Windows Community Toolkit. + + Classes: + - UwpProvider: + - UwpConfig: + + UWP Toolkit Windows Controls MSAL Microsoft Graph AadLogin Login + false + true + 8.0 + Debug;Release;CI + AnyCPU;ARM;ARM64;x64;x86 + + + + + + + + + + + + + + + + + + + + + + diff --git a/Microsoft.Toolkit.Graph.Providers.Uwp/Properties/AssemblyInfo.cs b/Microsoft.Toolkit.Graph.Providers.Uwp/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c244792 --- /dev/null +++ b/Microsoft.Toolkit.Graph.Providers.Uwp/Properties/AssemblyInfo.cs @@ -0,0 +1,11 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Resources; +using System.Runtime.CompilerServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: NeutralResourcesLanguage("en-US")] \ No newline at end of file diff --git a/Microsoft.Toolkit.Graph.Providers.Uwp/Properties/Microsoft.Toolkit.Graph.Providers.Uwp.rd.xml b/Microsoft.Toolkit.Graph.Providers.Uwp/Properties/Microsoft.Toolkit.Graph.Providers.Uwp.rd.xml new file mode 100644 index 0000000..db84211 --- /dev/null +++ b/Microsoft.Toolkit.Graph.Providers.Uwp/Properties/Microsoft.Toolkit.Graph.Providers.Uwp.rd.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/Microsoft.Toolkit.Graph.Providers/Uwp/WindowsConfig.cs b/Microsoft.Toolkit.Graph.Providers.Uwp/WindowsConfig.cs similarity index 100% rename from Microsoft.Toolkit.Graph.Providers/Uwp/WindowsConfig.cs rename to Microsoft.Toolkit.Graph.Providers.Uwp/WindowsConfig.cs diff --git a/Microsoft.Toolkit.Graph.Providers/Uwp/WindowsProvider.cs b/Microsoft.Toolkit.Graph.Providers.Uwp/WindowsProvider.cs similarity index 100% rename from Microsoft.Toolkit.Graph.Providers/Uwp/WindowsProvider.cs rename to Microsoft.Toolkit.Graph.Providers.Uwp/WindowsProvider.cs diff --git a/SampleTest/SampleTest.csproj b/SampleTest/SampleTest.csproj index 2d846ea..8e95ffc 100644 --- a/SampleTest/SampleTest.csproj +++ b/SampleTest/SampleTest.csproj @@ -165,6 +165,10 @@ {36d0b51d-111b-4fc3-84e0-ce085172b9cc} Microsoft.Toolkit.Graph.Providers.Msal + + {6bb9c83f-eaee-4d9c-b184-b8834592828b} + Microsoft.Toolkit.Graph.Providers.Uwp + {10dff17a-183c-4112-9b94-b9e2aac5e4c8} Microsoft.Toolkit.Graph.Providers diff --git a/Windows-Toolkit-Graph-Controls.sln b/Windows-Toolkit-Graph-Controls.sln index 833fd5c..17677e6 100644 --- a/Windows-Toolkit-Graph-Controls.sln +++ b/Windows-Toolkit-Graph-Controls.sln @@ -45,6 +45,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Toolkit.Graph.Pro {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8} = {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8} EndProjectSection EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Toolkit.Graph.Providers.Uwp", "Microsoft.Toolkit.Graph.Providers.Uwp\Microsoft.Toolkit.Graph.Providers.Uwp.csproj", "{6BB9C83F-EAEE-4D9C-B184-B8834592828B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution CI|Any CPU = CI|Any CPU @@ -438,6 +440,46 @@ Global {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Release|x64.Build.0 = Release|x64 {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Release|x86.ActiveCfg = Release|x86 {36D0B51D-111B-4FC3-84E0-CE085172B9CC}.Release|x86.Build.0 = Release|x86 + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.CI|Any CPU.ActiveCfg = CI|Any CPU + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.CI|Any CPU.Build.0 = CI|Any CPU + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.CI|ARM.ActiveCfg = CI|ARM + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.CI|ARM.Build.0 = CI|ARM + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.CI|ARM64.ActiveCfg = CI|ARM64 + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.CI|ARM64.Build.0 = CI|ARM64 + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.CI|x64.ActiveCfg = CI|x64 + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.CI|x64.Build.0 = CI|x64 + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.CI|x86.ActiveCfg = CI|x86 + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.CI|x86.Build.0 = CI|x86 + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Debug|ARM.ActiveCfg = Debug|ARM + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Debug|ARM.Build.0 = Debug|ARM + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Debug|ARM64.ActiveCfg = Debug|ARM64 + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Debug|ARM64.Build.0 = Debug|ARM64 + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Debug|x64.ActiveCfg = Debug|x64 + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Debug|x64.Build.0 = Debug|x64 + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Debug|x86.ActiveCfg = Debug|x86 + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Debug|x86.Build.0 = Debug|x86 + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Native|Any CPU.ActiveCfg = Debug|Any CPU + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Native|Any CPU.Build.0 = Debug|Any CPU + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Native|ARM.ActiveCfg = Debug|ARM + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Native|ARM.Build.0 = Debug|ARM + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Native|ARM64.ActiveCfg = Debug|ARM64 + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Native|ARM64.Build.0 = Debug|ARM64 + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Native|x64.ActiveCfg = Debug|x64 + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Native|x64.Build.0 = Debug|x64 + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Native|x86.ActiveCfg = Debug|x86 + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Native|x86.Build.0 = Debug|x86 + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Release|Any CPU.Build.0 = Release|Any CPU + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Release|ARM.ActiveCfg = Release|ARM + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Release|ARM.Build.0 = Release|ARM + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Release|ARM64.ActiveCfg = Release|ARM64 + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Release|ARM64.Build.0 = Release|ARM64 + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Release|x64.ActiveCfg = Release|x64 + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Release|x64.Build.0 = Release|x64 + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Release|x86.ActiveCfg = Release|x86 + {6BB9C83F-EAEE-4D9C-B184-B8834592828B}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 291fdf02f4b5df08b81835cd13e84f336ae45762 Mon Sep 17 00:00:00 2001 From: Shane Weaver Date: Thu, 11 Feb 2021 15:21:44 -0800 Subject: [PATCH 08/16] Changing the Config dependency property to affect Page instead of all FrameworkElements --- Microsoft.Toolkit.Graph.Providers/Graph.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Microsoft.Toolkit.Graph.Providers/Graph.cs b/Microsoft.Toolkit.Graph.Providers/Graph.cs index 4f8d1e0..c6df39c 100644 --- a/Microsoft.Toolkit.Graph.Providers/Graph.cs +++ b/Microsoft.Toolkit.Graph.Providers/Graph.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; namespace Microsoft.Toolkit.Graph.Providers { @@ -48,7 +49,7 @@ public static void SetConfig(DependencyObject target, IGraphConfig value) /// The identifier for the Config dependency property. /// public static readonly DependencyProperty ConfigProperty = - DependencyProperty.RegisterAttached("Config", typeof(IGraphConfig), typeof(FrameworkElement), new PropertyMetadata(null, OnConfigChanged)); + DependencyProperty.RegisterAttached("Config", typeof(IGraphConfig), typeof(Page), new PropertyMetadata(null, OnConfigChanged)); private static void OnConfigChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { From 59728d52b5cec1f069467cf24448b793b0dc2adf Mon Sep 17 00:00:00 2001 From: Shane Weaver Date: Thu, 11 Feb 2021 15:36:18 -0800 Subject: [PATCH 09/16] Reverting changes to app manifest --- SampleTest/Package.appxmanifest | 80 ++++++++++++++++----------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/SampleTest/Package.appxmanifest b/SampleTest/Package.appxmanifest index c28745c..10c23c5 100644 --- a/SampleTest/Package.appxmanifest +++ b/SampleTest/Package.appxmanifest @@ -6,44 +6,44 @@ xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" IgnorableNamespaces="uap mp"> - - - - - - GraphControlsTestApp - Weaver - Assets\StoreLogo.png - - - - - - - - - - - - - - - - - - - - - - + + + + + + SampleTest + mhawker + Assets\StoreLogo.png + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 8723d3daadd14f03a4fae6ad230c088960e8b1fd Mon Sep 17 00:00:00 2001 From: Shane Weaver Date: Fri, 12 Feb 2021 09:48:10 -0800 Subject: [PATCH 10/16] Stylecop fixes --- Microsoft.Toolkit.Graph/Extensions/GraphExtensions.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Microsoft.Toolkit.Graph/Extensions/GraphExtensions.cs b/Microsoft.Toolkit.Graph/Extensions/GraphExtensions.cs index 67c65cd..9d7668a 100644 --- a/Microsoft.Toolkit.Graph/Extensions/GraphExtensions.cs +++ b/Microsoft.Toolkit.Graph/Extensions/GraphExtensions.cs @@ -66,9 +66,8 @@ public static async Task FindPersonAsync(this GraphSe .WithScopes(new string[] { "people.read" }) .GetAsync(); } - catch (Exception e) + catch { - } return new UserPeopleCollectionPage(); From af1aa548c632212ea0b271917539d1c0076202f4 Mon Sep 17 00:00:00 2001 From: Shane Weaver Date: Fri, 12 Feb 2021 10:05:21 -0800 Subject: [PATCH 11/16] Stylecop fixes, added comments --- .../MsalProvider.cs | 12 +++++++---- .../WindowsProvider.cs | 20 +++++++++++++------ .../HttpRequestMessageExtensions.cs | 4 ++-- .../IGraphConfig.cs | 2 +- .../MockConfig.cs | 4 ++-- .../WPF-Core-GraphApp/MainWindow.xaml | 6 +++--- 6 files changed, 30 insertions(+), 18 deletions(-) diff --git a/Microsoft.Toolkit.Graph.Providers.Msal/MsalProvider.cs b/Microsoft.Toolkit.Graph.Providers.Msal/MsalProvider.cs index 4110edd..2987e98 100644 --- a/Microsoft.Toolkit.Graph.Providers.Msal/MsalProvider.cs +++ b/Microsoft.Toolkit.Graph.Providers.Msal/MsalProvider.cs @@ -29,7 +29,7 @@ public class MsalProvider : BaseProvider protected IAuthenticationProvider Provider { get; set; } /// - /// Initializes a new instance of the class. . + /// Initializes a new instance of the class. . /// private MsalProvider() { @@ -38,8 +38,12 @@ private MsalProvider() /// /// Easily creates a from a config object. /// - /// - /// + /// + /// The configuration object used to initialize the provider. + /// + /// + /// A new instance of the MsalProvider. + /// public static MsalProvider Create(MsalConfig config) { return Create(config.ClientId, config.RedirectUri, config.Scopes.ToArray()); @@ -80,7 +84,7 @@ public static MsalProvider Create(string clientid, string redirectUri = "https:/ }; msal.Graph = new GraphServiceClient(msal); - msal.TrySilentSignInAsync(); + _ = msal.TrySilentSignInAsync(); return msal; } diff --git a/Microsoft.Toolkit.Graph.Providers.Uwp/WindowsProvider.cs b/Microsoft.Toolkit.Graph.Providers.Uwp/WindowsProvider.cs index ee13e04..c480679 100644 --- a/Microsoft.Toolkit.Graph.Providers.Uwp/WindowsProvider.cs +++ b/Microsoft.Toolkit.Graph.Providers.Uwp/WindowsProvider.cs @@ -56,10 +56,14 @@ public AuthenticatedUser(Windows.Security.Credentials.PasswordCredential tokenCr private string _clientId; /// - /// + /// Creates a new instance of the WindowsProvider with a WindowsConfig object. /// - /// - /// + /// + /// The configuration object used to initialize the provider. + /// + /// + /// A new instance of the WindowsProvider. + /// public static WindowsProvider Create(WindowsConfig config) { return Create(config.ClientId, config.Scopes.ToArray()); @@ -68,8 +72,12 @@ public static WindowsProvider Create(WindowsConfig config) /// /// Creates a new instance of the WindowsProvider and attempts to sign in silently. /// - /// - /// + /// + /// The clientId value used to initialize the provider. + /// + /// + /// The scope values used to initialize the provider. + /// /// A new instance of a WindowsProvider. public static WindowsProvider Create(string clientId, string[] scopes) { @@ -77,7 +85,7 @@ public static WindowsProvider Create(string clientId, string[] scopes) provider.Graph = new GraphServiceClient(provider); - provider.TrySilentSignInAsync(); + _ = provider.TrySilentSignInAsync(); return provider; } diff --git a/Microsoft.Toolkit.Graph.Providers/Extensions/HttpRequestMessageExtensions.cs b/Microsoft.Toolkit.Graph.Providers/Extensions/HttpRequestMessageExtensions.cs index 5b5e666..597d838 100644 --- a/Microsoft.Toolkit.Graph.Providers/Extensions/HttpRequestMessageExtensions.cs +++ b/Microsoft.Toolkit.Graph.Providers/Extensions/HttpRequestMessageExtensions.cs @@ -23,7 +23,7 @@ public static class HttpRequestMessageExtensions private const string Bearer = "Bearer"; private const string MockGraphToken = "{token:https://graph.microsoft.com/}"; - public static void AddSdkVersion(this HttpRequestMessage request) + internal static void AddSdkVersion(this HttpRequestMessage request) { if (request == null || request.Headers == null) { @@ -39,7 +39,7 @@ public static void AddSdkVersion(this HttpRequestMessage request) } } - public static void AddMockProviderToken(this HttpRequestMessage request) + internal static void AddMockProviderToken(this HttpRequestMessage request) { request .Headers diff --git a/Microsoft.Toolkit.Graph.Providers/IGraphConfig.cs b/Microsoft.Toolkit.Graph.Providers/IGraphConfig.cs index 49c5866..37886da 100644 --- a/Microsoft.Toolkit.Graph.Providers/IGraphConfig.cs +++ b/Microsoft.Toolkit.Graph.Providers/IGraphConfig.cs @@ -5,7 +5,7 @@ namespace Microsoft.Toolkit.Graph.Providers { /// - /// + /// An interface to base Graph configuration implementations on. /// public interface IGraphConfig { diff --git a/Microsoft.Toolkit.Graph.Providers/MockConfig.cs b/Microsoft.Toolkit.Graph.Providers/MockConfig.cs index 4877b34..c857a47 100644 --- a/Microsoft.Toolkit.Graph.Providers/MockConfig.cs +++ b/Microsoft.Toolkit.Graph.Providers/MockConfig.cs @@ -5,12 +5,12 @@ namespace Microsoft.Toolkit.Graph.Providers { /// - /// + /// The configuration for the MockProvider. /// public class MockConfig : IGraphConfig { /// - /// + /// Gets or sets a value indicating whether the provider should automatically sign in or not. /// public bool SignedIn { get; set; } = true; } diff --git a/Samples/XAML Islands/WPF-Core-GraphApp/MainWindow.xaml b/Samples/XAML Islands/WPF-Core-GraphApp/MainWindow.xaml index 073b839..1429795 100644 --- a/Samples/XAML Islands/WPF-Core-GraphApp/MainWindow.xaml +++ b/Samples/XAML Islands/WPF-Core-GraphApp/MainWindow.xaml @@ -21,10 +21,10 @@ See MSAL docs about running on .NET Core: https://aka.ms/msal-net-os-browser --> - - + From 3379d61cb0af345b2b32cbed383f769cfedfc36a Mon Sep 17 00:00:00 2001 From: Shane Weaver Date: Fri, 12 Feb 2021 10:13:12 -0800 Subject: [PATCH 12/16] Removed wpf project --- .../AssemblyInfo.cs | 14 -- .../Behaviors/BehaviorBase.cs | 169 ------------------ ...crosoft.Toolkit.Wpf.Graph.Providers.csproj | 30 ---- .../Providers/ScopeSetTypeConverter.cs | 45 ----- Windows-Toolkit-Graph-Controls.sln | 42 ----- 5 files changed, 300 deletions(-) delete mode 100644 Microsoft.Toolkit.Wpf.Graph.Providers/AssemblyInfo.cs delete mode 100644 Microsoft.Toolkit.Wpf.Graph.Providers/Behaviors/BehaviorBase.cs delete mode 100644 Microsoft.Toolkit.Wpf.Graph.Providers/Microsoft.Toolkit.Wpf.Graph.Providers.csproj delete mode 100644 Microsoft.Toolkit.Wpf.Graph.Providers/Providers/ScopeSetTypeConverter.cs diff --git a/Microsoft.Toolkit.Wpf.Graph.Providers/AssemblyInfo.cs b/Microsoft.Toolkit.Wpf.Graph.Providers/AssemblyInfo.cs deleted file mode 100644 index a06202d..0000000 --- a/Microsoft.Toolkit.Wpf.Graph.Providers/AssemblyInfo.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System.Windows; - -[assembly: ThemeInfo( - ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located - //(used if a resource is not found in the page, - // or application resource dictionaries) - ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located - //(used if a resource is not found in the page, - // app, or any theme specific resource dictionaries) -)] diff --git a/Microsoft.Toolkit.Wpf.Graph.Providers/Behaviors/BehaviorBase.cs b/Microsoft.Toolkit.Wpf.Graph.Providers/Behaviors/BehaviorBase.cs deleted file mode 100644 index 800df3c..0000000 --- a/Microsoft.Toolkit.Wpf.Graph.Providers/Behaviors/BehaviorBase.cs +++ /dev/null @@ -1,169 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System.Windows; -using Microsoft.Xaml.Behaviors; - -namespace Microsoft.Toolkit.Wpf.UI.Behaviors -{ - /// - /// INTERNAL DO NOT USE, please thumb-up this comment https://github.com/windows-toolkit/Microsoft.Toolkit.Win32/issues/93#issuecomment-545091683 if you think this would be useful to you. - /// Base class for behaviors that solves 2 problems: - /// 1. Prevent duplicate initialization that can happen (prevent multiple OnAttached calls); - /// 2. Whenever initially fails, this method will subscribe to to allow lazy initialization. - /// - /// The type of the associated object. - /// - /// - /// For more info, see https://github.com/windows-toolkit/WindowsCommunityToolkit/issues/1008. - /// - public abstract class BehaviorBase : Behavior - where T : UIElement - { - private bool _isAttaching; - private bool _isAttached; - - /// - /// Gets a value indicating whether this behavior is attached. - /// - /// - /// true if this behavior is attached; otherwise, false. - /// - protected bool IsAttached - { - get { return _isAttached; } - } - - /// - /// Called after the behavior is attached to the . - /// - /// - /// Override this to hook up functionality to the - /// - protected override void OnAttached() - { - base.OnAttached(); - - HandleAttach(); - - var frameworkElement = AssociatedObject as FrameworkElement; - if (frameworkElement != null) - { - frameworkElement.Loaded += OnAssociatedObjectLoaded; - frameworkElement.Unloaded += OnAssociatedObjectUnloaded; - frameworkElement.SizeChanged += OnAssociatedObjectSizeChanged; - } - } - - /// - /// Called when the behavior is being detached from its . - /// - /// - /// Override this to unhook functionality from the - /// - protected override void OnDetaching() - { - base.OnDetaching(); - - var frameworkElement = AssociatedObject as FrameworkElement; - if (frameworkElement != null) - { - frameworkElement.Loaded -= OnAssociatedObjectLoaded; - frameworkElement.Unloaded -= OnAssociatedObjectUnloaded; - frameworkElement.SizeChanged -= OnAssociatedObjectSizeChanged; - } - - HandleDetach(); - } - - /// - /// Called when the associated object has been loaded. - /// - protected virtual void OnAssociatedObjectLoaded() - { - } - - /// - /// Called when the associated object has been unloaded. - /// - protected virtual void OnAssociatedObjectUnloaded() - { - } - - /// - /// Initializes the behavior to the associated object. - /// - /// true if the initialization succeeded; otherwise false. - protected virtual bool Initialize() - { - return true; - } - - /// - /// Uninitializes the behavior from the associated object. - /// - /// true if uninitialization succeeded; otherwise false. - protected virtual bool Uninitialize() - { - return true; - } - - private void OnAssociatedObjectLoaded(object sender, RoutedEventArgs e) - { - if (!_isAttached) - { - HandleAttach(); - } - - OnAssociatedObjectLoaded(); - } - - private void OnAssociatedObjectUnloaded(object sender, RoutedEventArgs e) - { - OnAssociatedObjectUnloaded(); - - // Note: don't detach here, we'll let the behavior implementation take care of that - } - - private void OnAssociatedObjectSizeChanged(object sender, SizeChangedEventArgs e) - { - if (!_isAttached) - { - HandleAttach(); - } - } - - private void HandleAttach() - { - if (_isAttaching || _isAttached) - { - return; - } - - _isAttaching = true; - - var attached = Initialize(); - if (attached) - { - _isAttached = true; - } - - _isAttaching = false; - } - - private void HandleDetach() - { - if (!_isAttached) - { - return; - } - - var detached = Uninitialize(); - if (detached) - { - _isAttached = false; - } - } - } -} \ No newline at end of file diff --git a/Microsoft.Toolkit.Wpf.Graph.Providers/Microsoft.Toolkit.Wpf.Graph.Providers.csproj b/Microsoft.Toolkit.Wpf.Graph.Providers/Microsoft.Toolkit.Wpf.Graph.Providers.csproj deleted file mode 100644 index ae43cf0..0000000 --- a/Microsoft.Toolkit.Wpf.Graph.Providers/Microsoft.Toolkit.Wpf.Graph.Providers.csproj +++ /dev/null @@ -1,30 +0,0 @@ - - - - netcoreapp3.1 - true - AnyCPU;x86;x64 - Debug;Release;CI - - - - DOTNET - - - - - - - - - - - - - - - - - - - diff --git a/Microsoft.Toolkit.Wpf.Graph.Providers/Providers/ScopeSetTypeConverter.cs b/Microsoft.Toolkit.Wpf.Graph.Providers/Providers/ScopeSetTypeConverter.cs deleted file mode 100644 index 2ce2951..0000000 --- a/Microsoft.Toolkit.Wpf.Graph.Providers/Providers/ScopeSetTypeConverter.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.ComponentModel; -using System.Globalization; - -namespace Microsoft.Toolkit.Wpf.Graph.Providers -{ - /// - /// - /// - public class ScopeSetTypeConverter : TypeConverter - { - /// - public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) - { - return sourceType == typeof(string); - } - - /// - public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) - { - return ScopeSet.ConvertToScopeArray(value as string); - } - - /// - public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) - { - return destinationType == typeof(string[]); - } - - /// - public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) - { - if (value is ScopeSet set) - { - return string.Join(",", set); - } - - return null; - } - } -} \ No newline at end of file diff --git a/Windows-Toolkit-Graph-Controls.sln b/Windows-Toolkit-Graph-Controls.sln index 17677e6..b8b2294 100644 --- a/Windows-Toolkit-Graph-Controls.sln +++ b/Windows-Toolkit-Graph-Controls.sln @@ -36,8 +36,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WPF-Core-GraphApp", "Sample EndProject Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "WPF-Packaged-App", "Samples\XAML Islands\WPF-Packaged-App\WPF-Packaged-App.wapproj", "{FE713229-AEE5-489A-9251-C346A82C1AC3}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Toolkit.Wpf.Graph.Providers", "Microsoft.Toolkit.Wpf.Graph.Providers\Microsoft.Toolkit.Wpf.Graph.Providers.csproj", "{8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Toolkit.Graph.Providers", "Microsoft.Toolkit.Graph.Providers\Microsoft.Toolkit.Graph.Providers.csproj", "{10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Toolkit.Graph.Providers.Msal", "Microsoft.Toolkit.Graph.Providers.Msal\Microsoft.Toolkit.Graph.Providers.Msal.csproj", "{36D0B51D-111B-4FC3-84E0-CE085172B9CC}" @@ -320,46 +318,6 @@ Global {FE713229-AEE5-489A-9251-C346A82C1AC3}.Release|x86.ActiveCfg = Release|x86 {FE713229-AEE5-489A-9251-C346A82C1AC3}.Release|x86.Build.0 = Release|x86 {FE713229-AEE5-489A-9251-C346A82C1AC3}.Release|x86.Deploy.0 = Release|x86 - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.CI|Any CPU.ActiveCfg = CI|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.CI|Any CPU.Build.0 = CI|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.CI|ARM.ActiveCfg = CI|x86 - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.CI|ARM.Build.0 = CI|x86 - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.CI|ARM64.ActiveCfg = CI|x64 - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.CI|ARM64.Build.0 = CI|x64 - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.CI|x64.ActiveCfg = CI|x64 - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.CI|x64.Build.0 = CI|x64 - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.CI|x86.ActiveCfg = CI|x86 - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.CI|x86.Build.0 = CI|x86 - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Debug|ARM.ActiveCfg = Debug|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Debug|ARM.Build.0 = Debug|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Debug|ARM64.ActiveCfg = Debug|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Debug|ARM64.Build.0 = Debug|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Debug|x64.ActiveCfg = Debug|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Debug|x64.Build.0 = Debug|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Debug|x86.ActiveCfg = Debug|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Debug|x86.Build.0 = Debug|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Native|Any CPU.ActiveCfg = Debug|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Native|Any CPU.Build.0 = Debug|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Native|ARM.ActiveCfg = Debug|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Native|ARM.Build.0 = Debug|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Native|ARM64.ActiveCfg = Debug|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Native|ARM64.Build.0 = Debug|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Native|x64.ActiveCfg = Debug|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Native|x64.Build.0 = Debug|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Native|x86.ActiveCfg = Debug|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Native|x86.Build.0 = Debug|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Release|Any CPU.Build.0 = Release|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Release|ARM.ActiveCfg = Release|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Release|ARM.Build.0 = Release|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Release|ARM64.ActiveCfg = Release|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Release|ARM64.Build.0 = Release|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Release|x64.ActiveCfg = Release|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Release|x64.Build.0 = Release|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Release|x86.ActiveCfg = Release|Any CPU - {8B9BFE42-F526-4961-A1FD-2D2B6AA0C305}.Release|x86.Build.0 = Release|Any CPU {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.CI|Any CPU.ActiveCfg = CI|Any CPU {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.CI|Any CPU.Build.0 = CI|Any CPU {10DFF17A-183C-4112-9B94-B9E2AAC5E4C8}.CI|ARM.ActiveCfg = CI|ARM From 148be5974f8aa72803eb0525ed6d31ae07e210fe Mon Sep 17 00:00:00 2001 From: Shane Weaver Date: Fri, 12 Feb 2021 10:45:55 -0800 Subject: [PATCH 13/16] Fixed duplicate project id --- .../Microsoft.Toolkit.Graph.Providers.Uwp.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Microsoft.Toolkit.Graph.Providers.Uwp/Microsoft.Toolkit.Graph.Providers.Uwp.csproj b/Microsoft.Toolkit.Graph.Providers.Uwp/Microsoft.Toolkit.Graph.Providers.Uwp.csproj index bda6318..8a71155 100644 --- a/Microsoft.Toolkit.Graph.Providers.Uwp/Microsoft.Toolkit.Graph.Providers.Uwp.csproj +++ b/Microsoft.Toolkit.Graph.Providers.Uwp/Microsoft.Toolkit.Graph.Providers.Uwp.csproj @@ -3,7 +3,7 @@ uap10.0.17763 Windows Community Toolkit Uwp Graph Provider - Microsoft.Toolkit.Graph.Providers.Msal + Microsoft.Toolkit.Graph.Providers.Uwp This library provides an IProvider implenetation that authenticates using the native Windows dialoges. It is part of the Windows Community Toolkit. From 9db9164a7ac9b9348025a612d8d97d72d40dd5a8 Mon Sep 17 00:00:00 2001 From: Shane Weaver Date: Fri, 12 Feb 2021 11:13:19 -0800 Subject: [PATCH 14/16] Fix bad name --- .../Microsoft.Toolkit.Graph.Providers.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Microsoft.Toolkit.Graph.Providers/Microsoft.Toolkit.Graph.Providers.csproj b/Microsoft.Toolkit.Graph.Providers/Microsoft.Toolkit.Graph.Providers.csproj index 226cd6d..b30053d 100644 --- a/Microsoft.Toolkit.Graph.Providers/Microsoft.Toolkit.Graph.Providers.csproj +++ b/Microsoft.Toolkit.Graph.Providers/Microsoft.Toolkit.Graph.Providers.csproj @@ -3,7 +3,7 @@ uap10.0.17763 Windows Community Toolkit Graph Providers - Microsoft.Toolkit.Graph.Controls + Microsoft.Toolkit.Graph.Providers This library provides base constructs for building Microsoft Graph XAML providers. It is part of the Windows Community Toolkit. From 6c0b1a46f97aab97baca4fec26bbf3f6d265d0e0 Mon Sep 17 00:00:00 2001 From: Shane Weaver Date: Thu, 18 Feb 2021 15:37:46 -0800 Subject: [PATCH 15/16] Update Microsoft.Toolkit.Graph.Providers/Graph.cs to work from app.xaml Co-authored-by: Michael Hawker MSFT (XAML Llama) <24302614+michael-hawker@users.noreply.github.com> --- Microsoft.Toolkit.Graph.Providers/Graph.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Microsoft.Toolkit.Graph.Providers/Graph.cs b/Microsoft.Toolkit.Graph.Providers/Graph.cs index c6df39c..2a33c9f 100644 --- a/Microsoft.Toolkit.Graph.Providers/Graph.cs +++ b/Microsoft.Toolkit.Graph.Providers/Graph.cs @@ -23,7 +23,7 @@ public static class Graph /// /// The value of the property on the target. /// - public static IGraphConfig GetConfig(DependencyObject target) + public static IGraphConfig GetConfig(ResourceDictionary target) { return (IGraphConfig)target.GetValue(ConfigProperty); } @@ -37,7 +37,7 @@ public static IGraphConfig GetConfig(DependencyObject target) /// /// The value to apply to the target property. /// - public static void SetConfig(DependencyObject target, IGraphConfig value) + public static void SetConfig(ResourceDictionary target, IGraphConfig value) { target.SetValue(ConfigProperty, value); } @@ -49,7 +49,7 @@ public static void SetConfig(DependencyObject target, IGraphConfig value) /// The identifier for the Config dependency property. /// public static readonly DependencyProperty ConfigProperty = - DependencyProperty.RegisterAttached("Config", typeof(IGraphConfig), typeof(Page), new PropertyMetadata(null, OnConfigChanged)); + DependencyProperty.RegisterAttached("Config", typeof(IGraphConfig), typeof(Graph), new PropertyMetadata(null, OnConfigChanged)); private static void OnConfigChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { From e441d6be1e86706d47ba0fc091eac1afddcd84bc Mon Sep 17 00:00:00 2001 From: Shane Weaver Date: Thu, 18 Feb 2021 16:03:12 -0800 Subject: [PATCH 16/16] Updated sample app to have config in app.xaml --- .../Controls/LoginButton/LoginButton.cs | 2 ++ Microsoft.Toolkit.Graph.Providers/Graph.cs | 24 ++++++++++++------- SampleTest/App.xaml | 21 +++++++++++++++- SampleTest/MainPage.xaml | 13 ---------- 4 files changed, 37 insertions(+), 23 deletions(-) diff --git a/Microsoft.Toolkit.Graph.Controls/Controls/LoginButton/LoginButton.cs b/Microsoft.Toolkit.Graph.Controls/Controls/LoginButton/LoginButton.cs index bb7c505..37d6362 100644 --- a/Microsoft.Toolkit.Graph.Controls/Controls/LoginButton/LoginButton.cs +++ b/Microsoft.Toolkit.Graph.Controls/Controls/LoginButton/LoginButton.cs @@ -110,6 +110,8 @@ private async void LoadData() } else if (provider.State == ProviderState.SignedIn) { + IsLoading = true; + try { // https://github.com/microsoftgraph/microsoft-graph-toolkit/blob/master/src/components/mgt-login/mgt-login.ts#L139 diff --git a/Microsoft.Toolkit.Graph.Providers/Graph.cs b/Microsoft.Toolkit.Graph.Providers/Graph.cs index 2a33c9f..6976608 100644 --- a/Microsoft.Toolkit.Graph.Providers/Graph.cs +++ b/Microsoft.Toolkit.Graph.Providers/Graph.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using Windows.UI.Xaml; -using Windows.UI.Xaml.Controls; namespace Microsoft.Toolkit.Graph.Providers { @@ -53,17 +52,24 @@ public static void SetConfig(ResourceDictionary target, IGraphConfig value) private static void OnConfigChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { - IGraphConfig config = GetConfig(sender); - - Type configType = config.GetType(); - if (_providers.ContainsKey(configType)) + if (sender is ResourceDictionary rd) { - var providerFactory = _providers[configType]; - ProviderManager.Instance.GlobalProvider = providerFactory.Invoke(config); + IGraphConfig config = GetConfig(rd); + + Type configType = config.GetType(); + if (_providers.ContainsKey(configType)) + { + var providerFactory = _providers[configType]; + ProviderManager.Instance.GlobalProvider = providerFactory.Invoke(config); + } + else if (config is MockConfig mockConfig) + { + ProviderManager.Instance.GlobalProvider = new MockProvider(mockConfig); + } } - else if (config is MockConfig mockConfig) + else { - ProviderManager.Instance.GlobalProvider = new MockProvider(mockConfig); + ProviderManager.Instance.GlobalProvider = null; } } diff --git a/SampleTest/App.xaml b/SampleTest/App.xaml index ea9689d..313f7e0 100644 --- a/SampleTest/App.xaml +++ b/SampleTest/App.xaml @@ -1,4 +1,23 @@  + xmlns:providers="using:Microsoft.Toolkit.Graph.Providers"> + + + + + + + + + + + + diff --git a/SampleTest/MainPage.xaml b/SampleTest/MainPage.xaml index f3a78c5..6008d19 100644 --- a/SampleTest/MainPage.xaml +++ b/SampleTest/MainPage.xaml @@ -13,19 +13,6 @@ xmlns:wgt="using:Microsoft.Toolkit.Graph.Controls" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" mc:Ignorable="d"> - - - - - -