Exemple #1
0
        public async Task <IActionResult> Edit(EditOpenIdScopeViewModel model, string returnUrl = null)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageScopes))
            {
                return(Forbid());
            }

            var scope = await _scopeManager.FindByPhysicalIdAsync(model.Id);

            if (scope == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var other = await _scopeManager.FindByNameAsync(model.Name);

                if (other != null && !string.Equals(
                        await _scopeManager.GetIdAsync(other),
                        await _scopeManager.GetIdAsync(scope)))
                {
                    ModelState.AddModelError(nameof(model.Name), S["The name is already taken by another scope."]);
                }
            }

            if (!ModelState.IsValid)
            {
                ViewData["ReturnUrl"] = returnUrl;
                return(View(model));
            }

            var descriptor = new OpenIdScopeDescriptor();
            await _scopeManager.PopulateAsync(descriptor, scope);

            descriptor.Description = model.Description;
            descriptor.DisplayName = model.DisplayName;
            descriptor.Name        = model.Name;

            descriptor.Resources.Clear();

            if (!string.IsNullOrEmpty(model.Resources))
            {
                descriptor.Resources.UnionWith(model.Resources.Split(' ', StringSplitOptions.RemoveEmptyEntries));
            }

            descriptor.Resources.UnionWith(model.Tenants
                                           .Where(tenant => tenant.Selected)
                                           .Where(tenant => !string.Equals(tenant.Name, _shellSettings.Name))
                                           .Select(tenant => OpenIdConstants.Prefixes.Tenant + tenant.Name));

            await _scopeManager.UpdateAsync(scope, descriptor);

            if (string.IsNullOrEmpty(returnUrl))
            {
                return(RedirectToAction("Index"));
            }

            return(LocalRedirect(returnUrl));
        }
Exemple #2
0
        public async Task ExecuteAsync(RecipeExecutionContext context)
        {
            if (!string.Equals(context.Name, "OpenIdScope", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var model = context.Step.ToObject <OpenIdScopeStepModel>();
            var scope = await _scopeManager.FindByNameAsync(model.ScopeName);

            var descriptor = new OpenIdScopeDescriptor();
            var isNew      = true;

            if (scope != null)
            {
                isNew = false;
                await _scopeManager.PopulateAsync(scope, descriptor);
            }

            descriptor.Description = model.Description;
            descriptor.Name        = model.ScopeName;
            descriptor.DisplayName = model.DisplayName;

            if (!string.IsNullOrEmpty(model.Resources))
            {
                descriptor.Resources.Clear();
                descriptor.Resources.UnionWith(
                    model.Resources
                    .Split(' ', StringSplitOptions.RemoveEmptyEntries));
            }

            if (isNew)
            {
                await _scopeManager.CreateAsync(descriptor);
            }
            else
            {
                await _scopeManager.UpdateAsync(scope, descriptor);
            }
        }