public AbstractClientHandle(global::IdentityServer3.Core.Models.Client client)
 {
     if (client != null)
     {
         AbsoluteRefreshTokenLifetime = client.AbsoluteRefreshTokenLifetime;
         AccessTokenLifetime          = client.AccessTokenLifetime;
         AccessTokenType = client.AccessTokenType;
         AllowAccessToAllCustomGrantTypes = client.AllowAccessToAllCustomGrantTypes;
         AllowAccessToAllScopes           = client.AllowAccessToAllScopes;
         AllowAccessTokensViaBrowser      = client.AllowAccessTokensViaBrowser;
         AllowClientCredentialsOnly       = client.AllowClientCredentialsOnly;
         AllowedCorsOrigins        = Serialize(client.AllowedCorsOrigins);
         AllowedCustomGrantTypes   = Serialize(client.AllowedCustomGrantTypes);
         AllowedScopes             = Serialize(client.AllowedScopes);
         AllowRememberConsent      = client.AllowRememberConsent;
         AlwaysSendClientClaims    = client.AlwaysSendClientClaims;
         AuthorizationCodeLifetime = client.AuthorizationCodeLifetime;
         Claims                           = Serialize(client.Claims);
         ClientId                         = client.ClientId;
         ClientName                       = client.ClientName;
         ClientSecrets                    = Serialize(client.ClientSecrets);
         ClientUri                        = client.ClientUri;
         Enabled                          = client.Enabled;
         EnableLocalLogin                 = client.EnableLocalLogin;
         Flow                             = client.Flow;
         IdentityProviderRestrictions     = Serialize(client.IdentityProviderRestrictions);
         IdentityTokenLifetime            = client.IdentityTokenLifetime;
         IncludeJwtId                     = client.IncludeJwtId;
         LogoUri                          = client.LogoUri;
         LogoutSessionRequired            = client.LogoutSessionRequired;
         LogoutUri                        = client.LogoutUri;
         PostLogoutRedirectUris           = Serialize(client.PostLogoutRedirectUris);
         PrefixClientClaims               = client.PrefixClientClaims;
         RedirectUris                     = Serialize(client.RedirectUris);
         RefreshTokenExpiration           = client.RefreshTokenExpiration;
         RefreshTokenUsage                = client.RefreshTokenUsage;
         RequireConsent                   = client.RequireConsent;
         RequireSignOutPrompt             = client.RequireSignOutPrompt;
         SlidingRefreshTokenLifetime      = client.SlidingRefreshTokenLifetime;
         UpdateAccessTokenClaimsOnRefresh = client.UpdateAccessTokenClaimsOnRefresh;
     }
 }
예제 #2
0
 public async Task CreateClientAsync(global::IdentityServer3.Core.Models.Client client)
 {
     await ClientStore.CreateClientAsync(client);
 }
예제 #3
0
        public async Task Test_Create_Modify_ClientAsync()
        {
            var dao = new IdentityServer3CassandraDao();
            await dao.EstablishConnectionAsync();

            var adminStore = new IdentityServer3AdminStore();

            global::IdentityServer3.Core.Models.Client dd = new global::IdentityServer3.Core.Models.Client();
            var insert = await CassandraTestHelper.InsertTestData_Clients(1);

            var result = await adminStore.FindClientByIdAsync(insert[0].ClientId);

            Assert.AreEqual(insert[0].ClientName, result.ClientName);
            int           expectedInt    = 1961;
            string        expectedString = Guid.NewGuid().ToString();
            List <string> expectedList   = new List <string>()
            {
                expectedString
            };

            #region PROPERTY_VALUES

            List <PropertyValue> propertyList = new List <PropertyValue>
            {
                new PropertyValue()
                {
                    Name  = "Claims",
                    Value = new List <Claim>()
                    {
                        new Claim("Type:" + expectedString, "Value:" + expectedString, "ValueType:" + expectedString, "Issuer:" + expectedString, "OriginalIssuer:" + expectedString,
                                  new ClaimsIdentity(new List <Claim>()
                        {
                            new Claim("Type:" + expectedString, "Value:" + expectedString)
                        }))
                    }
                },
                new PropertyValue()
                {
                    Name  = "ClientSecrets",
                    Value = new List <Secret>
                    {
                        new Secret(expectedString.Sha256()),
                    }
                },
                new PropertyValue()
                {
                    Name  = "ClientUri",
                    Value = expectedString
                },
                new PropertyValue()
                {
                    Name  = "ClientName",
                    Value = expectedString
                },
                new PropertyValue()
                {
                    Name  = "AbsoluteRefreshTokenLifetime",
                    Value = expectedInt
                },
                new PropertyValue()
                {
                    Name  = "AccessTokenLifetime",
                    Value = expectedInt
                },
                new PropertyValue()
                {
                    Name  = "AccessTokenType",
                    Value = expectedInt
                },
                new PropertyValue()
                {
                    Name  = "AllowAccessToAllCustomGrantTypes",
                    Value = !result.AllowAccessToAllCustomGrantTypes
                },
                new PropertyValue()
                {
                    Name  = "AllowAccessToAllScopes",
                    Value = !result.AllowAccessToAllScopes
                },
                new PropertyValue()
                {
                    Name  = "AllowAccessTokensViaBrowser",
                    Value = !result.AllowAccessTokensViaBrowser
                },
                new PropertyValue()
                {
                    Name  = "AllowClientCredentialsOnly",
                    Value = !result.AllowClientCredentialsOnly
                },
                new PropertyValue()
                {
                    Name  = "AllowRememberConsent",
                    Value = !result.AllowRememberConsent
                },
                new PropertyValue()
                {
                    Name  = "AlwaysSendClientClaims",
                    Value = !result.AlwaysSendClientClaims
                },
                new PropertyValue()
                {
                    Name  = "AuthorizationCodeLifetime",
                    Value = expectedInt
                },
                new PropertyValue()
                {
                    Name  = "Enabled",
                    Value = !result.Enabled
                },
                new PropertyValue()
                {
                    Name  = "EnableLocalLogin",
                    Value = !result.EnableLocalLogin
                },
                new PropertyValue()
                {
                    Name  = "Flow",
                    Value = expectedInt
                },
                new PropertyValue()
                {
                    Name  = "IdentityTokenLifetime",
                    Value = expectedInt
                },
                new PropertyValue()
                {
                    Name  = "IncludeJwtId",
                    Value = !result.IncludeJwtId
                },
                new PropertyValue()
                {
                    Name  = "LogoutSessionRequired",
                    Value = !result.LogoutSessionRequired
                },
                new PropertyValue()
                {
                    Name  = "LogoutUri",
                    Value = expectedString
                },
                new PropertyValue()
                {
                    Name  = "PrefixClientClaims",
                    Value = !result.PrefixClientClaims
                },
                new PropertyValue()
                {
                    Name  = "RefreshTokenExpiration",
                    Value = expectedInt
                },
                new PropertyValue()
                {
                    Name  = "RefreshTokenUsage",
                    Value = expectedInt
                },
                new PropertyValue()
                {
                    Name  = "RequireConsent",
                    Value = !result.RequireConsent
                },
                new PropertyValue()
                {
                    Name  = "RequireSignOutPrompt",
                    Value = !result.RequireSignOutPrompt
                },
                new PropertyValue()
                {
                    Name  = "SlidingRefreshTokenLifetime",
                    Value = expectedInt
                },
                new PropertyValue()
                {
                    Name  = "UpdateAccessTokenClaimsOnRefresh",
                    Value = !result.UpdateAccessTokenClaimsOnRefresh
                },
                new PropertyValue()
                {
                    Name  = "AllowedCorsOrigins",
                    Value = expectedList
                },
                new PropertyValue()
                {
                    Name  = "AllowedCustomGrantTypes",
                    Value = expectedList
                },
                new PropertyValue()
                {
                    Name  = "AllowedScopes",
                    Value = expectedList
                },
                new PropertyValue()
                {
                    Name  = "IdentityProviderRestrictions",
                    Value = expectedList
                },
                new PropertyValue()
                {
                    Name  = "PostLogoutRedirectUris",
                    Value = expectedList
                },
                new PropertyValue()
                {
                    Name  = "RedirectUris",
                    Value = expectedList
                },
                new PropertyValue()
                {
                    Name  = "LogoUri",
                    Value = expectedString
                },
            };
            #endregion

            await dao.UpdateClientByIdAsync(result.ClientId, propertyList);

            var result2 = await dao.FindClientByClientIdAsync(insert[0].ClientId);

            foreach (var property in propertyList)
            {
                var castTo      = property.Value.GetType();
                var valueRaw    = result2.GetPropertyValue(property.Name);
                var valueActual = Cast(valueRaw, castTo);

                var valueExpected = property.Value;
                if (castTo == typeof(List <string>))
                {
                    var propertyValue = (List <string>)Convert.ChangeType(property.Value, castTo);
                    var resultValue   = (List <string>)Convert.ChangeType(valueRaw, castTo);
                    Assert.AreEqual(propertyValue.Count, resultValue.Count);
                    var v = from x in propertyValue
                            where !resultValue.Contains(x)
                            select x;
                    Assert.IsFalse(v.Any());
                }
                else if (castTo == typeof(List <Secret>))
                {
                    var propertyValue = (List <Secret>)Convert.ChangeType(property.Value, castTo);
                    var resultValue   = (List <Secret>)Convert.ChangeType(valueRaw, castTo);
                    Assert.AreEqual(propertyValue.Count, resultValue.Count);

                    IEnumerable <Secret> except =
                        propertyValue.Except(resultValue, SecretComparer.OrdinalIgnoreCase);
                    Assert.IsFalse(except.Any());
                }
                else if (castTo == typeof(List <Claim>))
                {
                    var propertyValue = (List <Claim>)Convert.ChangeType(property.Value, castTo);
                    var resultValue   = (List <Claim>)Convert.ChangeType(valueRaw, castTo);
                    Assert.AreEqual(propertyValue.Count, resultValue.Count);

                    IEnumerable <Claim> except =
                        propertyValue.Except(resultValue, ClaimComparer.MinimalComparer);
                    Assert.IsFalse(except.Any());
                }

                else
                {
                    Assert.AreEqual(valueActual, valueExpected);
                }
            }
        }
        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);
        }
예제 #5
0
        public static ClientHandle ToClientHandle(this global::IdentityServer3.Core.Models.Client client)
        {
            var handle = new ClientHandle(client);

            return(handle);
        }