コード例 #1
0
        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);
        }