public async Task <ActionResult> New(ScopeNewModel model) { try { Scope scope = new Scope { Name = model.Name, Type = model.SelectedScopeType, Enabled = true }; var adminStore = new IdentityServer3AdminStore(); var scopeCheck = await adminStore.FindScopeByNameAsync(scope.Name); if (scopeCheck == null) { await adminStore.CreateScopeAsync(scope); // Good doesn't exist return(RedirectToAction("Index")); } ModelState.AddModelError(string.Empty, string.Format("The scope, {0}, already exists.", scope.Name)); return(View(model)); } catch { return(View()); } }
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 UpsertScopeAsync(Scope scope) { if (scope == null) { throw new ArgumentNullException("scope"); } var adminStore = new IdentityServer3AdminStore(); await adminStore.CreateScopeAsync(scope); }
public async Task <ActionResult> Edit(ScopeNewModel model) { try { Scope scope = new Scope { Name = model.Name, Type = model.SelectedScopeType, Enabled = true }; var adminStore = new IdentityServer3AdminStore(); await adminStore.CreateScopeAsync(scope); return(RedirectToAction("Index")); } catch { return(View()); } }