diff --git a/src/BuildingBlocks/Authentication/OpenIdConnect/Masa.BuildingBlocks.Authentication.OpenIdConnect.Models/Constans/GrantType.cs b/src/BuildingBlocks/Authentication/OpenIdConnect/Masa.BuildingBlocks.Authentication.OpenIdConnect.Models/Constans/GrantType.cs index e84903ea9..8cd09ed80 100644 --- a/src/BuildingBlocks/Authentication/OpenIdConnect/Masa.BuildingBlocks.Authentication.OpenIdConnect.Models/Constans/GrantType.cs +++ b/src/BuildingBlocks/Authentication/OpenIdConnect/Masa.BuildingBlocks.Authentication.OpenIdConnect.Models/Constans/GrantType.cs @@ -22,4 +22,6 @@ public static class GrantType public const string LOCAL_PHONE = "local_phone"; public const string THIRD_PARTY_IDP = "third_party_idp"; + + public const string LDAP = "ldap"; } diff --git a/src/BuildingBlocks/Authentication/OpenIdConnect/Masa.BuildingBlocks.Authentication.OpenIdConnect.Models/Constans/GrantTypes.cs b/src/BuildingBlocks/Authentication/OpenIdConnect/Masa.BuildingBlocks.Authentication.OpenIdConnect.Models/Constans/GrantTypes.cs index d30065b25..2d9030aa8 100644 --- a/src/BuildingBlocks/Authentication/OpenIdConnect/Masa.BuildingBlocks.Authentication.OpenIdConnect.Models/Constans/GrantTypes.cs +++ b/src/BuildingBlocks/Authentication/OpenIdConnect/Masa.BuildingBlocks.Authentication.OpenIdConnect.Models/Constans/GrantTypes.cs @@ -12,7 +12,7 @@ public class GrantTypes new[] { GrantType.IMPLICIT, GrantType.CLIENT_CREDENTIALS }; public static ICollection Code => - new[] { GrantType.AUTHORIZATION_CODE, GrantType.PHONE_CODE, GrantType.LOCAL_PHONE, GrantType.THIRD_PARTY_IDP }; + new[] { GrantType.AUTHORIZATION_CODE, GrantType.PHONE_CODE, GrantType.LOCAL_PHONE, GrantType.THIRD_PARTY_IDP, GrantType.LDAP }; public static ICollection CodeAndClientCredentials => new[] { GrantType.AUTHORIZATION_CODE, GrantType.CLIENT_CREDENTIALS }; diff --git a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/LdapOptionsModel.cs b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/LdapOptionsModel.cs new file mode 100644 index 000000000..78913af9d --- /dev/null +++ b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/LdapOptionsModel.cs @@ -0,0 +1,34 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the MIT License. See LICENSE.txt in the project root for license information. + +namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model; + +public class LdapOptionsModel +{ + public string ServerAddress { get; set; } + + public int ServerPort { get; set; } + + public int ServerPortSsl { get; set; } + + public string BaseDn { get; set; } + + public string UserSearchBaseDn { get; set; } + + public string GroupSearchBaseDn { get; set; } + + public string RootUserDn { get; set; } + + public string RootUserPassword { get; set; } + + public LdapOptionsModel(string serverAddress, int serverPort, string baseDn, string userSearchBaseDn, string groupSearchBaseDn, string rootUserDn, string rootUserPassword) + { + ServerAddress = serverAddress; + ServerPort = serverPort; + BaseDn = baseDn; + UserSearchBaseDn = userSearchBaseDn; + GroupSearchBaseDn = groupSearchBaseDn; + RootUserDn = rootUserDn; + RootUserPassword = rootUserPassword; + } +} diff --git a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/LoginByLdapModel.cs b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/LoginByLdapModel.cs new file mode 100644 index 000000000..e1983ed55 --- /dev/null +++ b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth.Contracts/Model/LoginByLdapModel.cs @@ -0,0 +1,17 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the MIT License. See LICENSE.txt in the project root for license information. + +namespace Masa.BuildingBlocks.StackSdks.Auth.Contracts.Model; + +public class LoginByLdapModel +{ + public string ClientId { get; set; } = ""; + + public string ClientSecret { get; set; } = ""; + + public List Scope { get; set; } = new() { "openid", "profile" }; + + public string UserName { get; set; } + + public string Scheme { get; set; } = "Ldap"; +} diff --git a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth/Service/ILoginService.cs b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth/Service/ILoginService.cs index 7a82869e7..ba5e5e8f2 100644 --- a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth/Service/ILoginService.cs +++ b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth/Service/ILoginService.cs @@ -10,4 +10,6 @@ public interface ILoginService Task LoginByPhoneNumberAsync(LoginByPhoneNumberFromSsoModel login); Task LoginByThirdPartyIdpAsync(LoginByThirdPartyIdpModel login); + + Task LoginByLdapAsync(LoginByLdapModel login); } diff --git a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth/Service/IThirdPartyIdpService.cs b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth/Service/IThirdPartyIdpService.cs index 1a9bd04c9..b20ee8904 100644 --- a/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth/Service/IThirdPartyIdpService.cs +++ b/src/BuildingBlocks/StackSdks/Auth/Masa.BuildingBlocks.StackSdks.Auth/Service/IThirdPartyIdpService.cs @@ -8,4 +8,6 @@ public interface IThirdPartyIdpService Task> GetAllAsync(); Task> GetAllFromCacheAsync(); + + Task GetLdapOptionsAsync(string scheme); } diff --git a/src/Contrib/Authentication/OpenIdConnect/Masa.Contrib.Authentication.OpenIdConnect.Cache/Caches/ApiResourceCache.cs b/src/Contrib/Authentication/OpenIdConnect/Masa.Contrib.Authentication.OpenIdConnect.Cache/Caches/ApiResourceCache.cs index 28460a17a..bbb455e9b 100644 --- a/src/Contrib/Authentication/OpenIdConnect/Masa.Contrib.Authentication.OpenIdConnect.Cache/Caches/ApiResourceCache.cs +++ b/src/Contrib/Authentication/OpenIdConnect/Masa.Contrib.Authentication.OpenIdConnect.Cache/Caches/ApiResourceCache.cs @@ -3,7 +3,6 @@ namespace Masa.Contrib.Authentication.OpenIdConnect.Cache.Caches; -[ExcludeFromCodeCoverage] public class ApiResourceCache : IApiResourceCache { private readonly IMultilevelCacheClient _memoryCacheClient; diff --git a/src/Contrib/Authentication/OpenIdConnect/Masa.Contrib.Authentication.OpenIdConnect.Cache/Caches/ApiScopeCache.cs b/src/Contrib/Authentication/OpenIdConnect/Masa.Contrib.Authentication.OpenIdConnect.Cache/Caches/ApiScopeCache.cs index f27bf4c22..59d2a039b 100644 --- a/src/Contrib/Authentication/OpenIdConnect/Masa.Contrib.Authentication.OpenIdConnect.Cache/Caches/ApiScopeCache.cs +++ b/src/Contrib/Authentication/OpenIdConnect/Masa.Contrib.Authentication.OpenIdConnect.Cache/Caches/ApiScopeCache.cs @@ -3,7 +3,6 @@ namespace Masa.Contrib.Authentication.OpenIdConnect.Cache.Caches; -[ExcludeFromCodeCoverage] public class ApiScopeCache : IApiScopeCache { private readonly IMultilevelCacheClient _memoryCacheClient; diff --git a/src/Contrib/Authentication/OpenIdConnect/Masa.Contrib.Authentication.OpenIdConnect.Cache/Caches/ClientCache.cs b/src/Contrib/Authentication/OpenIdConnect/Masa.Contrib.Authentication.OpenIdConnect.Cache/Caches/ClientCache.cs index 73bff4752..016247ebb 100644 --- a/src/Contrib/Authentication/OpenIdConnect/Masa.Contrib.Authentication.OpenIdConnect.Cache/Caches/ClientCache.cs +++ b/src/Contrib/Authentication/OpenIdConnect/Masa.Contrib.Authentication.OpenIdConnect.Cache/Caches/ClientCache.cs @@ -3,7 +3,6 @@ namespace Masa.Contrib.Authentication.OpenIdConnect.Cache.Caches; -[ExcludeFromCodeCoverage] public class ClientCache : IClientCache { private readonly IMultilevelCacheClient _memoryCacheClient; diff --git a/src/Contrib/Authentication/OpenIdConnect/Masa.Contrib.Authentication.OpenIdConnect.Cache/Caches/IdentityResourceCache.cs b/src/Contrib/Authentication/OpenIdConnect/Masa.Contrib.Authentication.OpenIdConnect.Cache/Caches/IdentityResourceCache.cs index a46583a68..dd8545679 100644 --- a/src/Contrib/Authentication/OpenIdConnect/Masa.Contrib.Authentication.OpenIdConnect.Cache/Caches/IdentityResourceCache.cs +++ b/src/Contrib/Authentication/OpenIdConnect/Masa.Contrib.Authentication.OpenIdConnect.Cache/Caches/IdentityResourceCache.cs @@ -3,8 +3,6 @@ namespace Masa.Contrib.Authentication.OpenIdConnect.Cache.Caches; - -[ExcludeFromCodeCoverage] public class IdentityResourceCache : IIdentityResourceCache { private readonly IMultilevelCacheClient _memoryCacheClient; diff --git a/src/Contrib/Authentication/OpenIdConnect/Tests/Masa.Contrib.Authentication.OpenIdConnect.Cache.Tests/ApiResourceCacheTest.cs b/src/Contrib/Authentication/OpenIdConnect/Tests/Masa.Contrib.Authentication.OpenIdConnect.Cache.Tests/ApiResourceCacheTest.cs new file mode 100644 index 000000000..1e9a8076c --- /dev/null +++ b/src/Contrib/Authentication/OpenIdConnect/Tests/Masa.Contrib.Authentication.OpenIdConnect.Cache.Tests/ApiResourceCacheTest.cs @@ -0,0 +1,76 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the MIT License. See LICENSE.txt in the project root for license information. + +namespace Masa.Contrib.Authentication.OpenIdConnect.Cache.Tests; + +[TestClass] +public class ApiResourceCacheTest +{ + IApiResourceCache _cache; + ApiResource _apiResource; + + [TestInitialize] + public void Initialized() + { + var options = new RedisConfigurationOptions() + { + Servers = new List + { + new RedisServerOptions + { + Host = "127.0.0.1", + Port = 6379 + } + } + }; + var serviceCollection = new ServiceCollection(); + serviceCollection.AddOidcCache(options); + _cache = serviceCollection.BuildServiceProvider().GetRequiredService(); + _apiResource = new ApiResource("ApiResourceCache", "ApiResourceCache", "ApiResourceCache", "", default, default, default, default); + } + + [TestMethod] + public async Task TestSetAsync() + { + await _cache.SetAsync(_apiResource); + var apiResources = await _cache.GetListAsync(); + Assert.IsTrue(apiResources.Any(item => item.Name == _apiResource.Name)); + } + + [TestMethod] + public async Task TestSetRangeAsync() + { + var input = new[] { _apiResource }; + await _cache.SetRangeAsync(input); + var apiResources = await _cache.GetListAsync(); + Assert.IsTrue(input.All(item => apiResources.Any(item2 => item2.Name == item.Name))); + } + + [TestMethod] + public async Task TestGetListAsync() + { + await _cache.SetAsync(_apiResource); + var apiResources = await _cache.GetListAsync(new[] { _apiResource.Name }); + Assert.IsTrue(apiResources.All(item => item.Name == _apiResource.Name)); + apiResources = await _cache.GetListAsync(); + Assert.IsTrue(apiResources.Any(item => item.Name == _apiResource.Name)); + } + + [TestMethod] + public async Task TestRemoveAsync() + { + await _cache.SetAsync(_apiResource); + await _cache.RemoveAsync(_apiResource); + var apiResources = await _cache.GetListAsync(); + Assert.IsTrue(apiResources.All(item => item.Name != _apiResource.Name)); + } + + [TestMethod] + public async Task TestResetAsync() + { + var input = new[] { _apiResource }; + await _cache.ResetAsync(input); + var apiResources = await _cache.GetListAsync(); + Assert.IsTrue(apiResources.Select(item => item.Name).Except(input.Select(item => item.Name)).Any() is false); + } +} diff --git a/src/Contrib/Authentication/OpenIdConnect/Tests/Masa.Contrib.Authentication.OpenIdConnect.Cache.Tests/ApiScopeCacheTest.cs b/src/Contrib/Authentication/OpenIdConnect/Tests/Masa.Contrib.Authentication.OpenIdConnect.Cache.Tests/ApiScopeCacheTest.cs new file mode 100644 index 000000000..0446deaa7 --- /dev/null +++ b/src/Contrib/Authentication/OpenIdConnect/Tests/Masa.Contrib.Authentication.OpenIdConnect.Cache.Tests/ApiScopeCacheTest.cs @@ -0,0 +1,76 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the MIT License. See LICENSE.txt in the project root for license information. + +namespace Masa.Contrib.Authentication.OpenIdConnect.Cache.Tests; + +[TestClass] +public class ApiScopeCacheTest +{ + IApiScopeCache _cache; + ApiScope _apiScope; + + [TestInitialize] + public void Initialized() + { + var options = new RedisConfigurationOptions() + { + Servers = new List + { + new RedisServerOptions + { + Host = "127.0.0.1", + Port = 6379 + } + } + }; + var serviceCollection = new ServiceCollection(); + serviceCollection.AddOidcCache(options); + _cache = serviceCollection.BuildServiceProvider().GetRequiredService(); + _apiScope = new ApiScope("ApiScope"); + } + + [TestMethod] + public async Task TestSetAsync() + { + await _cache.SetAsync(_apiScope); + var apiScopes = await _cache.GetListAsync(); + Assert.IsTrue(apiScopes.Any(item => item.Name == _apiScope.Name)); + } + + [TestMethod] + public async Task TestSetRangeAsync() + { + var input = new[] { _apiScope }; + await _cache.SetRangeAsync(input); + var apiScopes = await _cache.GetListAsync(); + Assert.IsTrue(input.All(item => apiScopes.Any(item2 => item2.Name == item.Name))); + } + + [TestMethod] + public async Task TestGetListAsync() + { + await _cache.SetAsync(_apiScope); + var apiScopes = await _cache.GetListAsync(new[] { _apiScope.Name }); + Assert.IsTrue(apiScopes.All(item => item.Name == _apiScope.Name)); + apiScopes = await _cache.GetListAsync(); + Assert.IsTrue(apiScopes.Any(item => item.Name == _apiScope.Name)); + } + + [TestMethod] + public async Task TestRemoveAsync() + { + await _cache.SetAsync(_apiScope); + await _cache.RemoveAsync(_apiScope); + var apiScopes = await _cache.GetListAsync(); + Assert.IsTrue(apiScopes.All(item => item.Name != _apiScope.Name)); + } + + [TestMethod] + public async Task TestResetAsync() + { + var input = new[] { _apiScope }; + await _cache.ResetAsync(input); + var apiScopes = await _cache.GetListAsync(); + Assert.IsTrue(apiScopes.Select(item => item.Name).Except(input.Select(item => item.Name)).Any() is false); + } +} diff --git a/src/Contrib/Authentication/OpenIdConnect/Tests/Masa.Contrib.Authentication.OpenIdConnect.Cache.Tests/ClientCacheTest.cs b/src/Contrib/Authentication/OpenIdConnect/Tests/Masa.Contrib.Authentication.OpenIdConnect.Cache.Tests/ClientCacheTest.cs new file mode 100644 index 000000000..ac5e18043 --- /dev/null +++ b/src/Contrib/Authentication/OpenIdConnect/Tests/Masa.Contrib.Authentication.OpenIdConnect.Cache.Tests/ClientCacheTest.cs @@ -0,0 +1,76 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the MIT License. See LICENSE.txt in the project root for license information. + +namespace Masa.Contrib.Authentication.OpenIdConnect.Cache.Tests; + +[TestClass] +public class ClientCacheTest +{ + IClientCache _cache; + Client _client; + + [TestInitialize] + public void Initialized() + { + var options = new RedisConfigurationOptions() + { + Servers = new List + { + new RedisServerOptions + { + Host = "127.0.0.1", + Port = 6379 + } + } + }; + var serviceCollection = new ServiceCollection(); + serviceCollection.AddOidcCache(options); + _cache = serviceCollection.BuildServiceProvider().GetRequiredService(); + _client = new Client(ClientTypes.Web, "Client", "Client"); + } + + [TestMethod] + public async Task TestSetAsync() + { + await _cache.SetAsync(_client); + var clients = await _cache.GetListAsync(new[] { _client.ClientName }); + Assert.IsTrue(clients.Any(item => item.ClientName == _client.ClientName)); + } + + [TestMethod] + public async Task TestSetRangeAsync() + { + var input = new[] { _client }; + await _cache.SetRangeAsync(input); + var clients = await _cache.GetListAsync(new[] { _client.ClientName }); + Assert.IsTrue(input.All(item => clients.Any(item2 => item2.ClientName == item.ClientName))); + } + + [TestMethod] + public async Task TestGetListAsync() + { + await _cache.SetAsync(_client); + var clients = await _cache.GetListAsync(new[] { _client.ClientName }); + Assert.IsTrue(clients.All(item => item.ClientName == _client.ClientName)); + clients = await _cache.GetListAsync(new[] { _client.ClientName }); + Assert.IsTrue(clients.Any(item => item.ClientName == _client.ClientName)); + } + + [TestMethod] + public async Task TestRemoveAsync() + { + await _cache.SetAsync(_client); + await _cache.RemoveAsync(_client); + var clients = await _cache.GetListAsync(new[] { _client.ClientName }); + Assert.IsTrue(clients.All(item => item.ClientName != _client.ClientName)); + } + + [TestMethod] + public async Task TestResetAsync() + { + var input = new[] { _client }; + await _cache.ResetAsync(input); + var clients = await _cache.GetListAsync(new[] { _client.ClientName }); + Assert.IsTrue(clients.Select(item => item.ClientName).Except(input.Select(item => item.ClientName)).Any() is false); + } +} diff --git a/src/Contrib/Authentication/OpenIdConnect/Tests/Masa.Contrib.Authentication.OpenIdConnect.Cache.Tests/IdentityResourceCacheTest.cs b/src/Contrib/Authentication/OpenIdConnect/Tests/Masa.Contrib.Authentication.OpenIdConnect.Cache.Tests/IdentityResourceCacheTest.cs new file mode 100644 index 000000000..f2e536787 --- /dev/null +++ b/src/Contrib/Authentication/OpenIdConnect/Tests/Masa.Contrib.Authentication.OpenIdConnect.Cache.Tests/IdentityResourceCacheTest.cs @@ -0,0 +1,76 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the MIT License. See LICENSE.txt in the project root for license information. + +namespace Masa.Contrib.Authentication.OpenIdConnect.Cache.Tests; + +[TestClass] +public class IdentityResourceCacheTest +{ + IIdentityResourceCache _cache; + IdentityResource _identityResource; + + [TestInitialize] + public void Initialized() + { + var options = new RedisConfigurationOptions() + { + Servers = new List + { + new RedisServerOptions + { + Host = "127.0.0.1", + Port = 6379 + } + } + }; + var serviceCollection = new ServiceCollection(); + serviceCollection.AddOidcCache(options); + _cache = serviceCollection.BuildServiceProvider().GetRequiredService(); + _identityResource = new IdentityResource("IdentityResource", "IdentityResource", "IdentityResource", default, default, default, default, default); + } + + [TestMethod] + public async Task TestSetAsync() + { + await _cache.SetAsync(_identityResource); + var identityResources = await _cache.GetListAsync(); + Assert.IsTrue(identityResources.Any(item => item.Name == _identityResource.Name)); + } + + [TestMethod] + public async Task TestSetRangeAsync() + { + var input = new[] { _identityResource }; + await _cache.SetRangeAsync(input); + var identityResources = await _cache.GetListAsync(); + Assert.IsTrue(input.All(item => identityResources.Any(item2 => item2.Name == item.Name))); + } + + [TestMethod] + public async Task TestGetListAsync() + { + await _cache.SetAsync(_identityResource); + var identityResources = await _cache.GetListAsync(new[] { _identityResource.Name }); + Assert.IsTrue(identityResources.All(item => item.Name == _identityResource.Name)); + identityResources = await _cache.GetListAsync(); + Assert.IsTrue(identityResources.Any(item => item.Name == _identityResource.Name)); + } + + [TestMethod] + public async Task TestRemoveAsync() + { + await _cache.SetAsync(_identityResource); + await _cache.RemoveAsync(_identityResource); + var identityResources = await _cache.GetListAsync(); + Assert.IsTrue(identityResources.All(item => item.Name != _identityResource.Name)); + } + + [TestMethod] + public async Task TestResetAsync() + { + var input = new[] { _identityResource }; + await _cache.ResetAsync(input); + var identityResources = await _cache.GetListAsync(); + Assert.IsTrue(identityResources.Select(item => item.Name).Except(input.Select(item => item.Name)).Any() is false); + } +} diff --git a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Auth/Service/LoginService.cs b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Auth/Service/LoginService.cs index c78b6673e..0de6e28f9 100644 --- a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Auth/Service/LoginService.cs +++ b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Auth/Service/LoginService.cs @@ -75,6 +75,25 @@ public async Task LoginByThirdPartyIdpAsync(Log }; } + public async Task LoginByLdapAsync(LoginByLdapModel login) + { + var client = CreateHttpClient(); + + var paramter = new Dictionary + { + ["client_Id"] = login.ClientId, + ["client_secret"] = login.ClientSecret, + ["grant_type"] = GrantType.LDAP, + ["scope"] = string.Join(' ', login.Scope), + ["userName"] = login.UserName, + ["scheme"] = login.Scheme + }; + + var tokenResponse = await RequestTokenRawAsync(client, paramter); + + return ToModel(tokenResponse); + } + HttpClient CreateHttpClient() { return _httpClientFactory.CreateClient(DEFAULT_SSO_CLIENT_NAME); diff --git a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Auth/Service/ThirdPartyIdpService.cs b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Auth/Service/ThirdPartyIdpService.cs index 32db45cf2..28ef0022b 100644 --- a/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Auth/Service/ThirdPartyIdpService.cs +++ b/src/Contrib/StackSdks/Masa.Contrib.StackSdks.Auth/Service/ThirdPartyIdpService.cs @@ -25,4 +25,10 @@ public async Task> GetAllFromCacheAsync() var thirdPartyIdps = await _memoryCacheClient.GetAsync>(CacheKeyConsts.ALL_THIRD_PARTY_IDP); return thirdPartyIdps ?? new(); } + + public Task GetLdapOptionsAsync(string scheme) + { + var requestUri = $"api/thirdPartyIdp/ldapOptions"; + return _caller.GetAsync(requestUri, new { scheme }); + } } diff --git a/src/Contrib/StackSdks/Tests/Masa.Contrib.StackSdks.Auth.Tests/ThirdPartyIdpServiceTest.cs b/src/Contrib/StackSdks/Tests/Masa.Contrib.StackSdks.Auth.Tests/ThirdPartyIdpServiceTest.cs index 7eee14db9..be3414006 100644 --- a/src/Contrib/StackSdks/Tests/Masa.Contrib.StackSdks.Auth.Tests/ThirdPartyIdpServiceTest.cs +++ b/src/Contrib/StackSdks/Tests/Masa.Contrib.StackSdks.Auth.Tests/ThirdPartyIdpServiceTest.cs @@ -31,4 +31,16 @@ public async Task TestGetAllFromCacheAsync() var result = await thirdPartyIdpService.GetAllFromCacheAsync(); multilevelCacheClient.Verify(provider => provider.GetAsync>(CacheKeyConsts.ALL_THIRD_PARTY_IDP, default), Times.Once); } + + [TestMethod] + public async Task TestGetLdapOptionsAsync() + { + var requestUri = $"api/thirdPartyIdp/ldapOptions"; + var caller = new Mock(); + caller.Setup(provider => provider.GetAsync(requestUri, It.IsAny(), default)).Verifiable(); + var multilevelCacheClient = new Mock(); + var thirdPartyIdpService = new ThirdPartyIdpService(caller.Object, multilevelCacheClient.Object); + var result = await thirdPartyIdpService.GetLdapOptionsAsync("ldap"); + caller.Verify(provider => provider.GetAsync(requestUri, It.IsAny(), default), Times.Once); + } }