Skip to content

Commit 9fc2a99

Browse files
authored
Support for injecting WebTokenRequest.Properties (#207)
* Add V2 model for Uwp authorization * Make v2 model only for MSA * Replace with new properties * Update comment * Remove null check
1 parent fce6356 commit 9fc2a99

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

CommunityToolkit.Authentication.Uwp/WebAccountProviderConfig.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using System.Collections.Generic;
6+
57
namespace CommunityToolkit.Authentication
68
{
79
/// <summary>
@@ -19,6 +21,16 @@ public struct WebAccountProviderConfig
1921
/// </summary>
2022
public WebAccountProviderType WebAccountProviderType { get; set; }
2123

24+
/// <summary>
25+
/// Gets or sets the properties that need to be added when constructing <see cref="Windows.Security.Authentication.Web.Core.WebTokenRequest"/> (for MSA).
26+
/// </summary>
27+
public IDictionary<string, string> MSATokenRequestProperties { get; set; }
28+
29+
/// <summary>
30+
/// Gets or sets the properties that need to be added when constructing <see cref="Windows.Security.Authentication.Web.Core.WebTokenRequest"/> (for AAD).
31+
/// </summary>
32+
public IDictionary<string, string> AADTokenRequestProperties { get; set; }
33+
2234
/// <summary>
2335
/// Initializes a new instance of the <see cref="WebAccountProviderConfig"/> struct.
2436
/// </summary>
@@ -28,6 +40,8 @@ public WebAccountProviderConfig(WebAccountProviderType webAccountProviderType, s
2840
{
2941
WebAccountProviderType = webAccountProviderType;
3042
ClientId = clientId;
43+
MSATokenRequestProperties = new Dictionary<string, string>();
44+
AADTokenRequestProperties = new Dictionary<string, string>();
3145
}
3246
}
3347
}

CommunityToolkit.Authentication.Uwp/WindowsProvider.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class WindowsProvider : BaseProvider
3333
private const string SettingsKeyProviderId = "WindowsProvider_ProviderId";
3434
private const string SettingsKeyProviderAuthority = "WindowsProvider_Authority";
3535

36-
private static readonly SemaphoreSlim SemaphoreSlim = new (1);
36+
private static readonly SemaphoreSlim SemaphoreSlim = new(1);
3737

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

552552
webTokenRequest.Properties.Add(GraphResourcePropertyKey, GraphResourcePropertyValue);
553+
if (provider.Authority == MicrosoftAccountAuthority)
554+
{
555+
foreach (var property in _webAccountProviderConfig.MSATokenRequestProperties)
556+
{
557+
webTokenRequest.Properties.Add(property);
558+
}
559+
}
560+
else if (provider.Authority == AadAuthority)
561+
{
562+
foreach (var property in _webAccountProviderConfig.AADTokenRequestProperties)
563+
{
564+
webTokenRequest.Properties.Add(property);
565+
}
566+
}
553567

554568
return webTokenRequest;
555569
}

0 commit comments

Comments
 (0)