public async Task <bool> UpsertClientAsync(FlattenedClientHandle client, CancellationToken cancellationToken = default(CancellationToken)) { try { if (client == null) { throw new ArgumentNullException("client"); } var session = CassandraSession; cancellationToken.ThrowIfCancellationRequested(); var batch = new BatchStatement(); var boundStatements = await BuildBoundStatements_ForCreate(client); batch.AddRange(boundStatements); await session.ExecuteAsync(batch).ConfigureAwait(false); return(true); } catch (Exception e) { throw; return(false); } }
public async Task <List <BoundStatement> > BuildBoundStatements_ForCreate( FlattenedClientHandle record) { var result = new List <BoundStatement>(); var client = record; PreparedStatement prepared = await _CreateClientById; BoundStatement bound = prepared.Bind( client.AbsoluteRefreshTokenLifetime, client.AccessTokenLifetime, (int)client.AccessTokenType, client.AllowAccessToAllCustomGrantTypes, client.AllowAccessToAllScopes, client.AllowAccessTokensViaBrowser, client.AllowClientCredentialsOnly, client.AllowedCorsOrigins, client.AllowedCustomGrantTypes, client.AllowedScopes, client.AllowRememberConsent, client.AlwaysSendClientClaims, client.AuthorizationCodeLifetime, client.Claims, client.ClientId, client.ClientName, client.ClientSecrets, client.ClientUri, client.Enabled, client.EnableLocalLogin, (int)client.Flow, client.IdentityProviderRestrictions, client.IdentityTokenLifetime, client.IncludeJwtId, client.LogoUri, client.LogoutSessionRequired, client.LogoutUri, client.PostLogoutRedirectUris, client.PrefixClientClaims, client.RedirectUris, (int)client.RefreshTokenExpiration, (int)client.RefreshTokenUsage, client.RequireConsent, client.RequireSignOutPrompt, client.SlidingRefreshTokenLifetime, client.UpdateAccessTokenClaimsOnRefresh ); result.Add(bound); return(result); }
public static async Task <List <FlattenedClientHandle> > InsertTestData_Clients(int count = 1) { var dao = new IdentityServer3CassandraDao(); await dao.EstablishConnectionAsync(); var insertScope = await InsertTestData_Scopes(3); var scopeNames = (from item in insertScope let c = item.Record.Name select c).ToList(); List <FlattenedClientHandle> result = new List <FlattenedClientHandle>(); for (int i = 0; i < count; ++i) { var name = "ClientName:" + Guid.NewGuid(); global::IdentityServer3.Core.Models.Client client = new global::IdentityServer3.Core.Models.Client() { AbsoluteRefreshTokenLifetime = 1, AccessTokenLifetime = 1, AccessTokenType = AccessTokenType.Jwt, AllowAccessToAllScopes = true, AllowAccessToAllCustomGrantTypes = true, AllowClientCredentialsOnly = true, AllowAccessTokensViaBrowser = true, AllowRememberConsent = true, AlwaysSendClientClaims = true, AuthorizationCodeLifetime = 1, AllowedCorsOrigins = new List <string>() { "AllowedCorsOrigins 1:" + i, "AllowedCorsOrigins 2:" + i }, AllowedCustomGrantTypes = new List <string>() { "AllowedCustomGrantTypes 1:" + i, "AllowedCustomGrantTypes 2:" + i }, AllowedScopes = scopeNames, ClientId = Guid.NewGuid().ToString(), ClientName = name, ClientUri = "ClientUri:" + i, Claims = new List <Claim>() { new Claim("Type:" + i, "Value:" + i, "ValueType:" + i, "Issuer:" + i, "OriginalIssuer:" + i, new ClaimsIdentity(new List <Claim>() { new Claim("Type:" + i, "Value:" + i) })) }, ClientSecrets = new List <Secret>() { new Secret("Value:" + i, "Description:" + i, DateTimeOffset.UtcNow) }, EnableLocalLogin = true, UpdateAccessTokenClaimsOnRefresh = true, Enabled = true, Flow = Flows.AuthorizationCode, RefreshTokenExpiration = TokenExpiration.Absolute, IncludeJwtId = true, LogoutSessionRequired = true, SlidingRefreshTokenLifetime = 1, IdentityTokenLifetime = 1, LogoUri = "LogoUri:" + i, LogoutUri = "LogoutUri:" + i, PrefixClientClaims = true, RequireConsent = true, RequireSignOutPrompt = true, RefreshTokenUsage = TokenUsage.OneTimeOnly, IdentityProviderRestrictions = new List <string>() { "IdentityProviderRestrictions 1:" + i, "IdentityProviderRestrictions 2:" + i }, RedirectUris = new List <string>() { "RedirectUris 1:" + i, "RedirectUris 2:" + i }, PostLogoutRedirectUris = new List <string>() { "PostLogoutRedirectUris 1:" + i, "PostLogoutRedirectUris 2:" + i } }; var clientrecord = new FlattenedClientHandle(client); await dao.UpsertClientAsync(clientrecord); result.Add(clientrecord); } return(result); }