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
14 changes: 14 additions & 0 deletions CommunityToolkit.Authentication.Uwp/WebAccountProviderConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// 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.Collections.Generic;

namespace CommunityToolkit.Authentication
{
/// <summary>
Expand All @@ -19,6 +21,16 @@ public struct WebAccountProviderConfig
/// </summary>
public WebAccountProviderType WebAccountProviderType { get; set; }

/// <summary>
/// Gets or sets the properties that need to be added when constructing <see cref="Windows.Security.Authentication.Web.Core.WebTokenRequest"/> (for MSA).
/// </summary>
public IDictionary<string, string> MSATokenRequestProperties { get; set; }

/// <summary>
/// Gets or sets the properties that need to be added when constructing <see cref="Windows.Security.Authentication.Web.Core.WebTokenRequest"/> (for AAD).
/// </summary>
public IDictionary<string, string> AADTokenRequestProperties { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="WebAccountProviderConfig"/> struct.
/// </summary>
Expand All @@ -28,6 +40,8 @@ public WebAccountProviderConfig(WebAccountProviderType webAccountProviderType, s
{
WebAccountProviderType = webAccountProviderType;
ClientId = clientId;
MSATokenRequestProperties = new Dictionary<string, string>();
AADTokenRequestProperties = new Dictionary<string, string>();
}
}
}
16 changes: 15 additions & 1 deletion CommunityToolkit.Authentication.Uwp/WindowsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class WindowsProvider : BaseProvider
private const string SettingsKeyProviderId = "WindowsProvider_ProviderId";
private const string SettingsKeyProviderAuthority = "WindowsProvider_Authority";

private static readonly SemaphoreSlim SemaphoreSlim = new (1);
private static readonly SemaphoreSlim SemaphoreSlim = new(1);

// Default/minimal scopes for authentication, if none are provided.
private static readonly string[] DefaultScopes = { "User.Read" };
Expand Down Expand Up @@ -550,6 +550,20 @@ private WebTokenRequest GetWebTokenRequest(WebAccountProvider provider, string c
: new WebTokenRequest(provider, scopesString, clientId);

webTokenRequest.Properties.Add(GraphResourcePropertyKey, GraphResourcePropertyValue);
if (provider.Authority == MicrosoftAccountAuthority)
{
foreach (var property in _webAccountProviderConfig.MSATokenRequestProperties)
{
webTokenRequest.Properties.Add(property);
}
}
else if (provider.Authority == AadAuthority)
{
foreach (var property in _webAccountProviderConfig.AADTokenRequestProperties)
{
webTokenRequest.Properties.Add(property);
}
}

return webTokenRequest;
}
Expand Down