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
This commit is contained in:
Richasy 2023-04-18 05:52:38 +08:00 коммит произвёл GitHub
Родитель fce6356681
Коммит 9fc2a992a0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 29 добавлений и 1 удалений

Просмотреть файл

@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System.Collections.Generic;
namespace CommunityToolkit.Authentication namespace CommunityToolkit.Authentication
{ {
/// <summary> /// <summary>
@ -19,6 +21,16 @@ namespace CommunityToolkit.Authentication
/// </summary> /// </summary>
public WebAccountProviderType WebAccountProviderType { get; set; } 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> /// <summary>
/// Initializes a new instance of the <see cref="WebAccountProviderConfig"/> struct. /// Initializes a new instance of the <see cref="WebAccountProviderConfig"/> struct.
/// </summary> /// </summary>
@ -28,6 +40,8 @@ namespace CommunityToolkit.Authentication
{ {
WebAccountProviderType = webAccountProviderType; WebAccountProviderType = webAccountProviderType;
ClientId = clientId; ClientId = clientId;
MSATokenRequestProperties = new Dictionary<string, string>();
AADTokenRequestProperties = new Dictionary<string, string>();
} }
} }
} }

Просмотреть файл

@ -33,7 +33,7 @@ namespace CommunityToolkit.Authentication
private const string SettingsKeyProviderId = "WindowsProvider_ProviderId"; private const string SettingsKeyProviderId = "WindowsProvider_ProviderId";
private const string SettingsKeyProviderAuthority = "WindowsProvider_Authority"; 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. // Default/minimal scopes for authentication, if none are provided.
private static readonly string[] DefaultScopes = { "User.Read" }; private static readonly string[] DefaultScopes = { "User.Read" };
@ -550,6 +550,20 @@ namespace CommunityToolkit.Authentication
: new WebTokenRequest(provider, scopesString, clientId); : new WebTokenRequest(provider, scopesString, clientId);
webTokenRequest.Properties.Add(GraphResourcePropertyKey, GraphResourcePropertyValue); 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; return webTokenRequest;
} }