public void Properties_Map() { Client model = new Client { Properties = { { "foo1", "bar1" }, { "foo2", "bar2" } } }; Entities.Client mappedEntity = model.ToEntity(); mappedEntity.Properties.Count.Should().Be(2); KeyValuePair <string, string> foo1 = mappedEntity.Properties.FirstOrDefault(x => x.Key == "foo1"); foo1.Should().NotBeNull(); foo1.Value.Should().Be("bar1"); KeyValuePair <string, string> foo2 = mappedEntity.Properties.FirstOrDefault(x => x.Key == "foo2"); foo2.Should().NotBeNull(); foo2.Value.Should().Be("bar2"); Client mappedModel = mappedEntity.ToModel(); mappedModel.Properties.Count.Should().Be(2); mappedModel.Properties.ContainsKey("foo1").Should().BeTrue(); mappedModel.Properties.ContainsKey("foo2").Should().BeTrue(); mappedModel.Properties["foo1"].Should().Be("bar1"); mappedModel.Properties["foo2"].Should().Be("bar2"); }
public async Task <Client> FindClientByIdAsync(string clientId) { Model.Client model = null; Entities.Client entity = await StorageContext.GetEntityBlobAsync <Entities.Client>(clientId, StorageContext.ClientBlobContainer); model = entity?.ToModel(); _logger.LogDebug("{clientName} found in blob storage: {clientFound}", clientId, model != null); return(model); }
public void Can_Map() { Client model = new Client(); Entities.Client mappedEntity = model.ToEntity(); Client mappedModel = mappedEntity.ToModel(); Assert.NotNull(mappedModel); Assert.NotNull(mappedEntity); }
private async Task <Models.Client> GetFromExpessionAsync <T>(T key, Expression <Func <Entities.Client, Boolean> > predicate) { Entities.Client client = await _context.Clients .Include(p => p.Policy) .ThenInclude(p => p.Roles) .Include(p => p.Policy) .ThenInclude(p => p.Permissions) .AsNoTracking() .FirstOrDefaultAsync(predicate); Models.Client model = client?.ToModel(); _logger.LogDebug($"{key} found in database: {model != null}"); return(model); }
public void missing_values_should_use_defaults() { Entities.Client entity = new Entities.Client { ClientSecrets = new List <Secret> { new Secret() } }; Client def = new Client { ClientSecrets = { new Models.Secret("foo") } }; Client model = entity.ToModel(); model.ProtocolType.Should().Be(def.ProtocolType); model.ClientSecrets.First().Type.Should().Be(def.ClientSecrets.First().Type); }
public void ToModel_MapsAllowedIdentityTokenSigningAlgorithms() { var client = new Entities.Client() { AllowedIdentityTokenSigningAlgorithms = "HS256,ES256" }; var entity = client.ToModel(); Assert.NotNull(entity.AllowedIdentityTokenSigningAlgorithms); Assert.NotEmpty(entity.AllowedIdentityTokenSigningAlgorithms); var algorithms = entity.AllowedIdentityTokenSigningAlgorithms.ToList(); var algorithmOne = algorithms[0]; var algorithmTwo = algorithms[1]; Assert.Equal("HS256", algorithmOne); Assert.Equal("ES256", algorithmTwo); }
/// <summary> /// Finds a client by id /// </summary> /// <param name="clientId">The client id</param> /// <returns> /// The client /// </returns> public Task <Client> FindClientByIdAsync(string clientId) { Entities.Client client = this._context.Clients .Include(x => x.AllowedGrantTypes) .Include(x => x.RedirectUris) .Include(x => x.PostLogoutRedirectUris) .Include(x => x.AllowedScopes) .Include(x => x.ClientSecrets) .Include(x => x.Claims) .Include(x => x.IdentityProviderRestrictions) .Include(x => x.AllowedCorsOrigins) .Include(x => x.Properties) .FirstOrDefault(x => x.ClientId == clientId); Client model = client?.ToModel(); this._logger.LogDebug( "{clientId} found in database: {clientIdFound}", clientId, model != null); return(Task.FromResult(model)); }
/// <summary> /// 根据客户端ID 获取客户端信息内容 /// </summary> /// <param name="clientId"></param> /// <returns></returns> public async Task <Client> FindClientByIdAsync(string clientId) { var cModel = new Client(); var _client = new Entities.Client(); using (var connection = new SqlConnection(_configurationStoreOptions.DbConnectionStrings)) { //由于后续未用到,暂不实现 ClientPostLogoutRedirectUris ClientClaims ClientIdPRestrictions ClientCorsOrigins ClientProperties,有需要的自行添加。 string sql = @"select * from Clients where ClientId=@client and Enabled=1; select t2.* from Clients t1 inner join ClientGrantTypes t2 on t1.Id=t2.ClientId where t1.ClientId=@client and Enabled=1; select t2.* from Clients t1 inner join ClientRedirectUris t2 on t1.Id=t2.ClientId where t1.ClientId=@client and Enabled=1; select t2.* from Clients t1 inner join ClientScopes t2 on t1.Id=t2.ClientId where t1.ClientId=@client and Enabled=1; select t2.* from Clients t1 inner join ClientSecrets t2 on t1.Id=t2.ClientId where t1.ClientId=@client and Enabled=1; "; var multi = await connection.QueryMultipleAsync(sql, new { client = clientId }); var client = multi.Read <Entities.Client>(); var ClientGrantTypes = multi.Read <Entities.ClientGrantType>(); var ClientRedirectUris = multi.Read <Entities.ClientRedirectUri>(); var ClientScopes = multi.Read <Entities.ClientScope>(); var ClientSecrets = multi.Read <Entities.ClientSecret>(); if (client != null && client.AsList().Count > 0) {//提取信息 _client = client.AsList()[0]; _client.AllowedGrantTypes = ClientGrantTypes.AsList(); _client.RedirectUris = ClientRedirectUris.AsList(); _client.AllowedScopes = ClientScopes.AsList(); _client.ClientSecrets = ClientSecrets.AsList(); cModel = _client.ToModel(); } } _logger.LogDebug("{clientId} found in database: {clientIdFound}", clientId, _client != null); return(cModel); }
public async Task <Models.Client> FindClientByIdAsync(string clientId) { var entity = new Entities.Client(); using (var connection = new SqlConnection(_dapperStoreOptions.DbConnectionString)) { var sql = $@" SELECT Id, Enabled, ClientId, ProtocolType, RequireClientSecret, ClientName, Description, ClientUri, LogoUri, RequireConsent, AllowRememberConsent, AlwaysIncludeUserClaimsInIdToken, RequirePkce, AllowPlainTextPkce, AllowAccessTokensViaBrowser, FrontChannelLogoutUri, FrontChannelLogoutSessionRequired, BackChannelLogoutUri, BackChannelLogoutSessionRequired, AllowOfflineAccess, IdentityTokenLifetime, AccessTokenLifetime, AuthorizationCodeLifetime, ConsentLifetime, AbsoluteRefreshTokenLifetime, SlidingRefreshTokenLifetime, RefreshTokenUsage, UpdateAccessTokenClaimsOnRefresh, RefreshTokenExpiration, AccessTokenType, EnableLocalLogin, IncludeJwtId, AlwaysSendClientClaims, ClientClaimsPrefix, PairWiseSubjectSalt, UserSsoLifetime, UserCodeType, DeviceCodeLifetime FROM Client WHERE ClientId = @clientId; SELECT A.Id, A.ClientId, A.Type, A.Value FROM ClientClaim AS A INNER JOIN Client AS B ON A.ClientId = B.Id WHERE B.ClientId = @clientId; SELECT A.Id, A.ClientId, A.Origin FROM ClientCorsOrigin AS A INNER JOIN Client AS B ON A.ClientId = B.Id WHERE B.ClientId = @clientId; SELECT A.Id, A.ClientId, A.GrantType FROM ClientGrantType AS A INNER JOIN Client AS B ON A.ClientId = B.Id WHERE B.ClientId = @clientId; SELECT A.Id, A.ClientId, A.Provider FROM ClientIdPRestriction AS A INNER JOIN Client AS B ON A.ClientId = B.Id WHERE B.ClientId = @clientId; SELECT A.Id, A.ClientId, A.PostLogoutRedirectUri FROM ClientPostLogoutRedirectUri AS A INNER JOIN Client AS B ON A.ClientId = B.Id WHERE B.ClientId = @clientId; SELECT A.Id, A.ClientId, A.K, A.V FROM ClientProperty AS A INNER JOIN Client AS B ON A.ClientId = B.Id WHERE B.ClientId = @clientId; SELECT A.Id, A.ClientId, A.RedirectUri FROM ClientRedirectUri AS A INNER JOIN Client AS B ON A.ClientId = B.Id WHERE B.ClientId = @clientId; SELECT A.Id, A.ClientId, A.Scope FROM ClientScope AS A INNER JOIN Client AS B ON A.ClientId = B.Id WHERE B.ClientId = @clientId; SELECT A.Id, A.ClientId, A.Description, A.Value, A.Expiration, A.Type FROM ClientSecret AS A INNER JOIN Client AS B ON A.ClientId = B.Id WHERE B.ClientId = @clientId; "; var reader = await connection.QueryMultipleAsync(sql, new { clientId }); var entityClients = reader.Read <Entities.Client>(); var entityClientClaims = reader.Read <Entities.ClientClaim>(); var entityClientCorsOrigins = reader.Read <Entities.ClientCorsOrigin>(); var entityClientGrantTypes = reader.Read <Entities.ClientGrantType>(); var entityClientIdPRestrictions = reader.Read <Entities.ClientIdPRestriction>(); var entityClientPostLogoutRedirectUris = reader.Read <Entities.ClientPostLogoutRedirectUri>(); var entityClientProperties = reader.Read <Entities.ClientProperty>(); var entityClientRedirectUris = reader.Read <Entities.ClientRedirectUri>(); var entityClientScopes = reader.Read <Entities.ClientScope>(); var entityClientSecrets = reader.Read <Entities.ClientSecret>(); if (entityClients != null && entityClients.AsList().Count > 0) { entity = entityClients.AsList()[0]; entity.ClientClaims = entityClientClaims.AsList(); entity.ClientCorsOrigins = entityClientCorsOrigins.AsList(); entity.ClientGrantTypes = entityClientGrantTypes.AsList(); entity.ClientIdPRestrictions = entityClientIdPRestrictions.AsList(); entity.ClientPostLogoutRedirectUris = entityClientPostLogoutRedirectUris.AsList(); entity.ClientProperties = entityClientProperties.AsList(); entity.ClientRedirectUris = entityClientRedirectUris.AsList(); entity.ClientScopes = entityClientScopes.AsList(); entity.ClientSecrets = entityClientSecrets.AsList(); return(entity.ToModel()); } } return(null); }