public async Task Test_Create_Add_AllowedCorsOrigins_ByClientIdAsync() { var adminStore = new IdentityServer3AdminStore(); var insert = await CassandraTestHelper.InsertTestData_Clients(1); var result = await adminStore.FindClientByIdAsync(insert[0].ClientId); Assert.AreEqual(insert[0].ClientName, result.ClientName); List <string> allowedCorsOrigins = new List <string>() { Guid.NewGuid().ToString() }; await adminStore.AddAllowedCorsOriginsToClientAsync(insert[0].ClientId, allowedCorsOrigins); var finalList = new List <string>(); finalList.AddRange(allowedCorsOrigins); finalList.AddRange(result.AllowedCorsOrigins); result = await adminStore.FindClientByIdAsync(insert[0].ClientId); Assert.AreEqual(result.AllowedCorsOrigins.Count(), finalList.Count); var ff = result.AllowedCorsOrigins.Except(finalList); Assert.IsFalse(ff.Any()); }
public async Task Test_Create_Add_ClientClaims_ByClientIdAsync() { var adminStore = new IdentityServer3AdminStore(); var insert = await CassandraTestHelper.InsertTestData_Clients(1); var result = await adminStore.FindClientByIdAsync(insert[0].ClientId); Assert.IsNotNull(result); Assert.AreEqual(insert[0].ClientName, result.ClientName); var original = result.Claims; var newClaims = new List <Claim> { new Claim(Constants.ClaimTypes.Subject, Guid.NewGuid().ToString()), new Claim(Constants.ClaimTypes.PreferredUserName, Guid.NewGuid().ToString()), }; var finalList = new List <Claim>(); finalList.AddRange(original); finalList.AddRange(newClaims); await adminStore.AddClaimsToClientAsync(insert[0].ClientId, newClaims); result = await adminStore.FindClientByIdAsync(insert[0].ClientId); Assert.IsNotNull(result); Assert.AreEqual(result.Claims.Count(), finalList.Count); var ff = result.Claims.Except(finalList, ClaimComparer.DeepComparer); Assert.IsFalse(ff.Any()); }
public async Task Test_Create_Add_RedirectUris_ByClientIdAsync() { var adminStore = new IdentityServer3AdminStore(); var insert = await CassandraTestHelper.InsertTestData_Clients(1); var result = await adminStore.FindClientByIdAsync(insert[0].ClientId); Assert.IsNotNull(result); var original = result.RedirectUris; Assert.AreEqual(insert[0].ClientName, result.ClientName); List <string> newData = new List <string>() { Guid.NewGuid().ToString() }; await adminStore.AddRedirectUrisToClientAsync(insert[0].ClientId, newData); var finalList = new List <string>(); finalList.AddRange(original); finalList.AddRange(newData); result = await adminStore.FindClientByIdAsync(insert[0].ClientId); Assert.IsNotNull(result); Assert.AreEqual(result.RedirectUris.Count(), finalList.Count); var ff = result.RedirectUris.Except(finalList); Assert.IsFalse(ff.Any()); }
public async Task Test_Create_Add_ScopeByClientIdAsync() { var insert = await CassandraTestHelper.InsertTestData_Clients(1); var adminStore = new IdentityServer3AdminStore(); // await adminStore.CleanupClientByIdAsync(insert[0].ClientId); var result = await adminStore.FindClientByIdAsync(insert[0].ClientId); var originalAllowedScopes = result.AllowedScopes; Assert.AreEqual(insert[0].ClientName, result.ClientName); List <Scope> scopes = new List <Scope>() { new Scope() { AllowUnrestrictedIntrospection = true, Name = Guid.NewGuid().ToString(), Enabled = true }, new Scope() { AllowUnrestrictedIntrospection = true, Name = Guid.NewGuid().ToString(), Enabled = true } }; foreach (var scope in scopes) { await adminStore.CreateScopeAsync(scope); } var query = from item in scopes let c = item.Name select c; List <string> addedScopeNames = query.ToList(); List <string> finalExpected = new List <string>(); finalExpected.AddRange(addedScopeNames); finalExpected.AddRange(result.AllowedScopes); await adminStore.AddScopesToClientAsync(insert[0].ClientId, addedScopeNames); result = await adminStore.FindClientByIdAsync(insert[0].ClientId); Assert.IsNotNull(result); Assert.AreEqual(result.AllowedScopes.Count(), finalExpected.Count); var ff = result.AllowedScopes.Except(finalExpected); Assert.IsFalse(ff.Any()); }
public async Task Test_Create_Delete_ByIdAsync() { var adminStore = new IdentityServer3AdminStore(); var insert = await CassandraTestHelper.InsertTestData_Clients(1); var result = await adminStore.FindClientByIdAsync(insert[0].ClientId); Assert.AreEqual(insert[0].ClientName, result.ClientName); await adminStore.DeleteClientAsync(insert[0].ClientId); result = await adminStore.FindClientByIdAsync(insert[0].ClientId); Assert.IsNull(result); }
public async Task Test_Create_Add_Delete_ClientSecrets_ByClientIdAsync() { var adminStore = new IdentityServer3AdminStore(); var insert = await CassandraTestHelper.InsertTestData_Clients(1); var result = await adminStore.FindClientByIdAsync(insert[0].ClientId); Assert.IsNotNull(result); Assert.AreEqual(insert[0].ClientName, result.ClientName); var original = result.ClientSecrets; List <Secret> newSecrets = new List <Secret>(); for (int i = 0; i < 2; ++i) { newSecrets.Add(new Secret() { Value = Guid.NewGuid().ToString(), Description = Guid.NewGuid().ToString(), Expiration = DateTimeOffset.UtcNow.AddHours(1), Type = Guid.NewGuid().ToString() }); } var finalList = new List <Secret>(); finalList.AddRange(original); finalList.AddRange(newSecrets); await adminStore.AddClientSecretsToClientAsync(insert[0].ClientId, newSecrets); result = await adminStore.FindClientByIdAsync(insert[0].ClientId); Assert.IsNotNull(result); Assert.AreEqual(result.ClientSecrets.Count(), finalList.Count); var ff = result.ClientSecrets.Except(finalList, SecretComparer.OrdinalIgnoreCase); Assert.IsFalse(ff.Any()); await adminStore.DeleteClientSecretsFromClientAsync(insert[0].ClientId, result.ClientSecrets); result = await adminStore.FindClientByIdAsync(insert[0].ClientId); Assert.IsNotNull(result); Assert.IsFalse(result.ClientSecrets.Any()); }
public async Task Test_Create_Page_ByClientIdAsync() { var dao = new IdentityServer3CassandraDao(); await dao.EstablishConnectionAsync(); await dao.TruncateTablesAsync(); int nNumber = 100; var adminStore = new IdentityServer3AdminStore(); var insert = await CassandraTestHelper.InsertTestData_Clients(nNumber); foreach (var item in insert) { var result = await adminStore.FindClientByIdAsync(item.ClientId); Assert.IsNotNull(result); Assert.AreEqual(item.ClientName, result.ClientName); } var pageSize = 9; byte[] pagingState = null; int runningCount = 0; do { var items = await adminStore.PageClientsAsync(pageSize, pagingState); pagingState = items.PagingState; runningCount += items.Count(); } while (pagingState != null); Assert.AreEqual(100, runningCount); }
public async Task <ActionResult> ManageScopes(string clientId) { var adminStore = new IdentityServer3AdminStore(); var userScopes = await adminStore.FindScopesByUserAsync(User.Identity.GetUserId()); var queryUserScopes = from item in userScopes let c = new ScopeEnabledRecord() { Enabled = false, Name = item } select c; var currentClient = await adminStore.FindClientByIdAsync(clientId); var queryAllowedScopes = from item in currentClient.AllowedScopes let c = new ScopeEnabledRecord() { Enabled = true, Name = item } select c; var model = new ClientScopeModel() { ClientId = clientId, UserScopes = queryUserScopes.ToList(), AllowedScopes = queryAllowedScopes.ToList() }; return(View(model)); }
public async Task Test_Create_Add_Delete_AllowedCustomGrantTypesByClientIdAsync() { var adminStore = new IdentityServer3AdminStore(); var insert = await CassandraTestHelper.InsertTestData_Clients(1); var result = await adminStore.FindClientByIdAsync(insert[0].ClientId); Assert.IsNotNull(result); var originalAllowedCustomGrantTypes = result.AllowedCustomGrantTypes; Assert.AreEqual(insert[0].ClientName, result.ClientName); List <string> newAllowedCustomGrantTypes = new List <string>() { Guid.NewGuid().ToString() }; var finalList = new List <string>(); finalList.AddRange(originalAllowedCustomGrantTypes); finalList.AddRange(newAllowedCustomGrantTypes); await adminStore.AddAllowedCustomGrantTypesToClientAsync(insert[0].ClientId, newAllowedCustomGrantTypes); result = await adminStore.FindClientByIdAsync(insert[0].ClientId); Assert.IsNotNull(result); Assert.AreEqual(result.AllowedCustomGrantTypes.Count(), finalList.Count); var ff = result.AllowedCustomGrantTypes.Except(finalList); Assert.IsFalse(ff.Any()); await adminStore.DeleteAllowedCustomGrantTypesFromClientAsync(insert[0].ClientId, result.AllowedCustomGrantTypes); result = await adminStore.FindClientByIdAsync(insert[0].ClientId); Assert.IsNotNull(result); Assert.IsFalse(result.AllowedCustomGrantTypes.Any()); }
/* * new Client * { * ClientName = "Silicon-only Client", * ClientId = "silicon", * Enabled = true, * Flow = Flows.ClientCredentials, * * ClientSecrets = new List<Secret> * { * new Secret("secret".Sha256()) * }, * * AllowedScopes = new List<string> * { * "api1" * }, * AccessTokenType = AccessTokenType.Reference * } * */ public async Task <ActionResult> Delete(string clientId) { var adminStore = new IdentityServer3AdminStore(); var client = await adminStore.FindClientByIdAsync(clientId); var clientVM = new ClientViewModel { ClientId = client.ClientId, ClientName = client.ClientName }; return(View(clientVM)); }
public async Task <ActionResult> Manage(string id) { var adminStore = new IdentityServer3AdminStore(); var userId = User.Identity.GetUserId(); var client = await adminStore.FindClientByIdAsync(id); ClientViewModel cvModel = new ClientViewModel() { AccessTokenType = client.AccessTokenType, AllowedScopes = client.AllowedScopes, ClientId = client.ClientId, ClientName = client.ClientName, ClientSecrets = client.ClientSecrets, Enabled = client.Enabled, Flow = client.Flow }; return(View(cvModel)); }
public async Task <ActionResult> Manage(ClientViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var adminStore = new IdentityServer3AdminStore(); var client = await adminStore.FindClientByIdAsync(model.ClientId); client.ClientName = model.ClientName; client.Enabled = model.Enabled; await adminStore.CreateClientAsync(client); var clients = new List <string> { client.ClientId }; await adminStore.AddClientIdToIdentityServerUserAsync(User.Identity.GetUserId(), clients); return(RedirectToAction("Index")); }
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); } } }