Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,18 @@
<PropertyGroup>
<TargetFramework>uap10.0.17134</TargetFramework>
<Title>Windows Community Toolkit Graph Uwp Authentication Provider</Title>
<PackageId>CommunityToolkit.Authentication.Uwp</PackageId>
<Description>
This library provides an authentication provider based on the native Windows dialogues. It is part of the Windows Community Toolkit.

Classes:
- WindowsProvider:
</Description>
<PackageTags>UWP Toolkit Windows Microsoft Graph AadLogin Authentication Login</PackageTags>
<SignAssembly>false</SignAssembly>
<GenerateLibraryLayout>true</GenerateLibraryLayout>
<LangVersion>8.0</LangVersion>
<Configurations>Debug;Release;CI</Configurations>
<Platforms>AnyCPU;ARM;ARM64;x64;x86</Platforms>
<LangVersion>9.0</LangVersion>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\CommunityToolkit.Authentication\CommunityToolkit.Authentication.csproj" />
</ItemGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'uap10.0.17134'">
<DefineConstants Condition="'$(DisableImplicitFrameworkDefines)' != 'true'">$(DefineConstants);WINRT</DefineConstants>
</PropertyGroup>

<Import Project="$(MSBuildSDKExtrasTargets)" Condition="Exists('$(MSBuildSDKExtrasTargets)')" />
<!-- https://weblogs.asp.net/rweigelt/disable-warnings-in-generated-c-files-of-uwp-app -->
<Target Name="PragmaWarningDisablePrefixer" AfterTargets="MarkupCompilePass2">
<ItemGroup>
<GeneratedCSFiles Include="**\*.g.cs;**\*.g.i.cs" />
</ItemGroup>
<Message Text="CSFiles: @(GeneratedCSFiles->'&quot;%(Identity)&quot;')" />
<Exec Command="for %%f in (@(GeneratedCSFiles->'&quot;%(Identity)&quot;')) do echo #pragma warning disable &gt; %%f.temp &amp;&amp; type %%f &gt;&gt; %%f.temp &amp;&amp; move /y %%f.temp %%f &gt; NUL" />
</Target>
</Project>
35 changes: 10 additions & 25 deletions CommunityToolkit.Graph.Uwp/CommunityToolkit.Graph.Uwp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<TargetFramework>uap10.0.17763</TargetFramework>
<Title>Windows Community Toolkit Graph Uwp Controls and Helpers</Title>
<PackageId>CommunityToolkit.Graph.Uwp</PackageId>
<Description>
This library provides Microsoft Graph UWP XAML controls. It is part of the Windows Community Toolkit.

Expand All @@ -14,51 +13,37 @@
- PeoplePicker: The PeoplePicker Control is a simple control that allows for selection of one or more users.
</Description>
<PackageTags>UWP Toolkit Windows Controls MSAL Microsoft Graph AadLogin ProfileCard Person PeoplePicker Login</PackageTags>
<SignAssembly>false</SignAssembly>
<GenerateLibraryLayout>true</GenerateLibraryLayout>
<LangVersion>9.0</LangVersion>
<Configurations>Debug;Release;CI</Configurations>
<Platforms>AnyCPU;ARM;ARM64;x64;x86</Platforms>
</PropertyGroup>

<ItemGroup>
<Content Include="Assets\person.png" />
</ItemGroup>

<ProjectReference Include="..\CommunityToolkit.Authentication\CommunityToolkit.Authentication.csproj" />
<ProjectReference Include="..\CommunityToolkit.Graph\CommunityToolkit.Graph.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Graph" Version="3.31.0" />
<PackageReference Include="Microsoft.Toolkit.Uwp.UI" Version="7.0.1" />
<PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls.Input" Version="7.0.1" />
</ItemGroup>


<ItemGroup>
<Content Include="Assets\person.png" />
</ItemGroup>

<ItemGroup>
<None Include="VisualStudioToolsManifest.xml" Pack="true" PackagePath="tools" />
<None Include="$(OutDir)\Design\$(MSBuildProjectName).Design*.dll;$(OutDir)\Design\$(MSBuildProjectName).Design*.pdb" Pack="true" PackagePath="lib\$(TargetFramework)\Design" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CommunityToolkit.Authentication\CommunityToolkit.Authentication.csproj" />
<ProjectReference Include="..\CommunityToolkit.Graph\CommunityToolkit.Graph.csproj" />
</ItemGroup>

<ItemGroup>
<Page Update="Controls\PersonView\PersonView.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>

<ItemGroup>
<Folder Include="Triggers\" />
</ItemGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'uap10.0.17763'">
<DefineConstants Condition="'$(DisableImplicitFrameworkDefines)' != 'true'">$(DefineConstants);WINRT</DefineConstants>
</PropertyGroup>

<Import Project="$(MSBuildSDKExtrasTargets)" Condition="Exists('$(MSBuildSDKExtrasTargets)')" />
<!-- https://weblogs.asp.net/rweigelt/disable-warnings-in-generated-c-files-of-uwp-app -->
<Target Name="PragmaWarningDisablePrefixer" AfterTargets="MarkupCompilePass2">
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,5 @@ public User UserDetails
/// </returns>
public static readonly DependencyProperty UserDetailsProperty =
DependencyProperty.Register(nameof(UserDetails), typeof(User), typeof(LoginButton), new PropertyMetadata(null));

/// <summary>
/// Gets or sets a value indicating whether the control is loading and has not established a sign-in state.
/// </summary>
public bool IsLoading
{
get { return (bool)GetValue(IsLoadingProperty); }
protected set { SetValue(IsLoadingProperty, value); }
}

/// <summary>
/// Identifies the <see cref="IsLoading"/> dependency property.
/// </summary>
/// <returns>
/// The identifier for the <see cref="IsLoading"/> dependency property.
/// </returns>
public static readonly DependencyProperty IsLoadingProperty =
DependencyProperty.Register(nameof(IsLoading), typeof(bool), typeof(LoginButton), new PropertyMetadata(true));
}
}
90 changes: 55 additions & 35 deletions CommunityToolkit.Graph.Uwp/Controls/LoginButton/LoginButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Threading.Tasks;
using CommunityToolkit.Authentication;
using CommunityToolkit.Graph.Extensions;
Expand All @@ -27,6 +26,21 @@ public partial class LoginButton : Control
private Button _loginButton;
private ButtonBase _signOutButton;

private bool _isLoading;

/// <summary>
/// Gets or sets a value indicating whether the control is loading and has not established a sign-in state.
/// </summary>
protected bool IsLoading
{
get => _isLoading;
set
{
_isLoading = value;
UpdateButtonEnablement();
}
}

/// <summary>
/// Initializes a new instance of the <see cref="LoginButton"/> class.
/// </summary>
Expand All @@ -37,14 +51,22 @@ public LoginButton()
ProviderManager.Instance.ProviderStateChanged += (sender, args) => LoadData();
}

/// <summary>
/// Update the enablement state of the button in relation to the _isLoading property.
/// </summary>
protected void UpdateButtonEnablement()
{
if (_loginButton != null)
{
_loginButton.IsEnabled = !_isLoading;
}
}

/// <inheritdoc/>
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();

IsLoading = true;
LoadData();

if (_loginButton != null)
{
_loginButton.Click -= LoginButton_Click;
Expand All @@ -68,6 +90,8 @@ protected override void OnApplyTemplate()
{
_signOutButton.Click += SignOutButton_Click;
}

LoadData();
}

private async void LoginButton_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -99,41 +123,37 @@ private async void SignOutButton_Click(object sender, RoutedEventArgs e)
private async void LoadData()
{
var provider = ProviderManager.Instance.GlobalProvider;

if (provider == null)
switch (provider?.State)
{
return;
}
case ProviderState.Loading:
IsLoading = true;
break;

if (provider.State == ProviderState.Loading)
{
IsLoading = true;
}
else if (provider.State == ProviderState.SignedIn)
{
try
{
// https://github.com/microsoftgraph/microsoft-graph-toolkit/blob/master/src/components/mgt-login/mgt-login.ts#L139
// TODO: Batch with photo request later? https://github.com/microsoftgraph/msgraph-sdk-dotnet-core/issues/29
UserDetails = await provider.GetClient().GetMeAsync();
}
catch (Exception e)
{
LoginFailed?.Invoke(this, new LoginFailedEventArgs(e));
}
case ProviderState.SignedIn:
try
{
IsLoading = true;

IsLoading = false;
}
else if (provider.State == ProviderState.SignedOut)
{
UserDetails = null; // What if this was user provided? Should we not hook into these events then?
// https://github.com/microsoftgraph/microsoft-graph-toolkit/blob/master/src/components/mgt-login/mgt-login.ts#L139
// TODO: Batch with photo request later? https://github.com/microsoftgraph/msgraph-sdk-dotnet-core/issues/29
UserDetails = await provider.GetClient().GetMeAsync();
}
catch (Exception e)
{
LoginFailed?.Invoke(this, new LoginFailedEventArgs(e));
}
finally
{
IsLoading = false;
}

IsLoading = false;
}
else
{
// Provider in Loading state
Debug.Fail("unsupported state");
break;

case ProviderState.SignedOut:
default:
UserDetails = null; // What if this was user provided? Should we not hook into these events then?
IsLoading = false;
break;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
<Button x:Name="PART_LoginButton"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
IsEnabled="{Binding IsLoading, Converter={StaticResource InverseBoolConverter}, RelativeSource={RelativeSource TemplatedParent}}">
BorderThickness="{TemplateBinding BorderThickness}">

<!-- Grid matches the height of the PersonView in OneLine view.
This prevents the vertical height from changing when transitioning between states. -->
Expand Down
1 change: 0 additions & 1 deletion Samples/ManualGraphRequestSample/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
IsActive="False" />
</StackPanel>


<ListView
Grid.Column="1"
Width="300"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ await App.DispatcherQueue.EnqueueAsync(async () =>
ProviderManager.Instance.ProviderStateChanged += (s, e) =>
{
var providerManager = s as ProviderManager;
if (e.Reason == ProviderManagerChangedState.ProviderStateChanged && providerManager.GlobalProvider.State == ProviderState.SignedIn)
if (providerManager.GlobalProvider.State == ProviderState.SignedIn)
{
test.Invoke();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ await App.DispatcherQueue.EnqueueAsync(async () =>
ProviderManager.Instance.ProviderStateChanged += (s, e) =>
{
var providerManager = s as ProviderManager;
if (e.Reason == ProviderManagerChangedState.ProviderStateChanged && providerManager.GlobalProvider.State == ProviderState.SignedIn)
if (providerManager.GlobalProvider.State == ProviderState.SignedIn)
{
test.Invoke();
}
Expand Down