Exemple #1
0
        public async Task <IActionResult> AddClients(ClientsViewModel args)
        {
            if (ModelState.IsValid)
            {
                var scoper = new List <ClientScope>();
                args.allowed_scopes?.ForEach(x => { scoper.Add(new ClientScope {
                        Scope = x
                    }); });
                var corss = new List <ClientCorsOrigin>();
                args.allowed_cors_origins?.ForEach(x => { corss.Add(new ClientCorsOrigin {
                        Origin = x
                    }); });
                var grants = new  List <ClientGrantType>();
                args.allowed_grant_types?.ForEach(x => { grants.Add(new ClientGrantType {
                        GrantType = x
                    }); });
                var client = new IdentityServer4.EntityFramework.Entities.Client
                {
                    ClientId      = args.client_id,
                    ClientName    = args.client_name,
                    ClientSecrets = new List <ClientSecret> {
                        new ClientSecret {
                            Value = args.client_secrets.Sha256()
                        }
                    },
                    AllowedScopes      = scoper,
                    AllowedCorsOrigins = corss,
                    // RedirectUris = new List<ClientRedirectUri> { new ClientRedirectUri { RedirectUri = args.redirect_uris } },
                    //PostLogoutRedirectUris = new List<ClientPostLogoutRedirectUri> { new ClientPostLogoutRedirectUri { PostLogoutRedirectUri=args.post_logout_redirect_uris} },
                    AllowedGrantTypes = grants
                };
                _context.Clients.Add(client);
                var resutlt = await _context.SaveChangesAsync();

                if (resutlt > 0)
                {
                    return(RedirectToAction("Clients"));
                }
                ModelState.AddModelError(string.Empty, "Client添加失败");
                return(View(args));
            }

            ModelState.AddModelError(string.Empty, "参数验证错误");
            return(RedirectToAction("AddClients"));
        }
Exemple #2
0
        public IActionResult AddClients()
        {
            var result = new ClientsViewModel
            {
                allowed_grant_types = new List <string>

                {
                    cons.GrantTypes.AuthorizationCode,
                    cons.GrantTypes.ClientCredentials,
                    cons.GrantTypes.DeviceCode,
                    cons.GrantTypes.Implicit,
                    cons.GrantTypes.JwtBearer,
                    cons.GrantTypes.Password,
                    cons.GrantTypes.RefreshToken,
                    cons.GrantTypes.Saml2Bearer,
                    cons.GrantTypes.TokenExchange
                }
            };

            return(View(result));
        }