public async Task <ApiResource> FindApiResourceAsync(string name) { var dataTables = Enumerable.Range(0, 5).Select(i => new DataTable()).ToArray(); await _dataFetcher.FillAsync(dataTables, "FindApiResourceByName", new SqlParameter("@Name", name)); var dtResource = dataTables[0]; var dtClaims = dataTables[1]; var dtProperties = dataTables[2]; var dtScopes = dataTables[3]; var dtScopeClaims = dataTables[3]; var dtSecrets = dataTables[4]; var rResource = dtResource.Rows[0] as DataRow; var resource = new ApiResource { Name = rResource["Name"].ToString(), DisplayName = rResource["Name"].ToString() }; foreach (DataRow row in dtClaims.Rows) { resource.UserClaims.Add(row["Claim"].ToString()); } foreach (DataRow row in dtProperties.Rows) { resource.Properties.Add(row["Key"].ToString(), row["Value"].ToString()); } foreach (DataRow row in dtScopes.Rows) { resource.Scopes.Add(new Scope { Name = row["ScopeName"].ToString(), DisplayName = row["DisplayName"].ToString(), Description = row["Description"].ToString(), Required = (bool)row["Required"], Emphasize = (bool)row["Emphasize"], ShowInDiscoveryDocument = (bool)row["ShowInDiscoveryDocument"] }); } foreach (DataRow row in dtScopeClaims.Rows) { var scopeName = row["ScopeName"].ToString(); var scope = resource.Scopes.Single(s => s.Name == scopeName); scope.UserClaims.Add(row["Claim"].ToString()); } foreach (DataRow row in dtSecrets.Rows) { resource.ApiSecrets.Add(new Secret(row["Secret"].ToString())); } return(resource); }
public async Task <Client> FindClientByIdAsync(string clientId) { var client = new Client(); var dataTables = Enumerable.Range(0, 6).Select(i => new DataTable()).ToArray(); await _dataFiller.FillAsync(dataTables, "FindClientById", new SqlParameter("@ClientId", clientId)); var dtClient = dataTables[0]; var dtProperties = dataTables[1]; var dtScopes = dataTables[2]; var dtSecrets = dataTables[3]; var dtGrantTypes = dataTables[4]; var dtCorsOrigins = dataTables[5]; if (dtClient.Rows.Count == 0) { throw new AuthenticationException(); } var rClient = dtClient.Rows[0] as DataRow; client.ClientId = rClient["ClientId"].ToString(); client.ClientName = rClient["ClientName"].ToString(); client.Enabled = (bool)rClient["Enabled"]; client.RequireClientSecret = (bool)rClient["RequireClientSecret"]; client.AllowOfflineAccess = (bool)rClient["AllowOfflineAccess"]; client.EnableLocalLogin = (bool)rClient["EnableLocalLogin"]; client.RequireConsent = (bool)rClient["RequireConsent"]; client.AllowRememberConsent = (bool)rClient["AllowRememberConsent"]; client.ClientUri = rClient["ClientUri"].ToString(); client.LogoUri = rClient["LogoUri"].ToString(); client.AccessTokenLifetime = 60 * (int)rClient["AccessTokenLifetimeMinutes"]; var redirectUri = rClient["RedirectUri"].ToString(); if (!string.IsNullOrEmpty(redirectUri)) { client.RedirectUris = new List <string> { redirectUri }; } var postLogRedirectUri = rClient["PostLogoutRedirectUri"].ToString(); if (!string.IsNullOrEmpty(postLogRedirectUri)) { client.PostLogoutRedirectUris = new List <string> { postLogRedirectUri }; } foreach (DataRow row in dtProperties.Rows) { client.Properties.Add(row["Key"].ToString(), row["Value"].ToString()); } foreach (DataRow row in dtSecrets.Rows) { client.ClientSecrets.Add(new Secret(row["Secret"].ToString())); } foreach (DataRow row in dtScopes.Rows) { client.AllowedScopes.Add(row["Scope"].ToString()); } foreach (DataRow row in dtGrantTypes.Rows) { client.AllowedGrantTypes.Add(row["GrantType"].ToString()); } foreach (DataRow row in dtCorsOrigins.Rows) { client.AllowedCorsOrigins.Add(row["CorsOrigin"].ToString()); } return(client); }