Esempio n. 1
0
        public async Task <IActionResult> Create(CreateOpenIdScopeViewModel model, string returnUrl = null)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageScopes))
            {
                return(Forbid());
            }

            if (await _scopeManager.FindByNameAsync(model.Name) != null)
            {
                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
            {
                Description = model.Description,
                DisplayName = model.DisplayName,
                Name        = model.Name
            };

            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.CreateAsync(descriptor);

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

            return(LocalRedirect(returnUrl));
        }
Esempio n. 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);
            }
        }