/// <summary> /// 根据客户端ID 获取客户端信息内容 /// </summary> /// <param name="clientId"></param> /// <returns></returns> public async Task <Client> FindClientByIdAsync(string clientId) { var cModel = new Client(); var s = new Secret("myblogsecret999".Sha256()); var _client = new Entity.Clients(); 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 <Client>(); var ClientGrantTypes = multi.Read <Entity.ClientGrantTypes>(); var ClientRedirectUris = multi.Read <Entity.ClientRedirectUris>(); var ClientScopes = multi.Read <Entity.ClientScopes>(); var ClientSecrets = multi.Read <Secret>(); if (client != null && client.AsList().Count > 0) {//提取信息 cModel = client.AsList()[0]; cModel.AllowedGrantTypes = ClientGrantTypes.Select(m => m.GrantType).AsList(); cModel.RedirectUris = ClientRedirectUris.Select(m => m.RedirectUri).AsList(); cModel.AllowedScopes = ClientScopes.Select(m => m.Scope).AsList(); cModel.ClientSecrets = ClientSecrets.AsList(); //_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 static Client ToModel(this Entity.Clients entity) { return(Mapper.Map <Client>(entity)); }