コード例 #1
0
        private static IEnumerable <ClientEntity> GetClientsInternal()
        {
            var internalClient = new List <Client>
            {
                new Client
                {
                    ClientId                    = "carstacksp",
                    ClientName                  = "CarStackSp",
                    AllowedGrantTypes           = GrantTypes.Implicit,
                    AllowAccessTokensViaBrowser = true,

                    RedirectUris           = { "http://localhost:4200/assets/signin-callback.html" },
                    PostLogoutRedirectUris = { "http://localhost:4200/index.html" },
                    AllowedCorsOrigins     = { "http://localhost:4200" },

                    AllowedScopes =
                    {
                        IdentityServerConstants.StandardScopes.OpenId,
                        "carstackapi"
                    }
                }
            };

            List <ClientEntity> clients = new List <ClientEntity>();

            foreach (var client in internalClient)
            {
                var clientEntity = new ClientEntity();

                clientEntity = clientEntity.AddDataToEntity(client);

                clients.Add(clientEntity);
            }
            return(clients);
        }
コード例 #2
0
ファイル: Config.cs プロジェクト: youlin1210/MySample
        public static IEnumerable <ClientEntity> GetClients()
        {
            List <ClientEntity> clients = new List <ClientEntity>();

            foreach (var client in GetClientsInternal())
            {
                var clientEntity = new ClientEntity
                {
                    Client = client
                };
                clientEntity.AddDataToEntity();
                clients.Add(clientEntity);
            }

            return(clients);
        }
コード例 #3
0
        private static void EnsureSeedData(MedParkContext context)
        {
            Console.WriteLine("Seeding database...");

            Console.WriteLine("Clients being populated");

            foreach (var client in IdentityConfig.GetClients())
            {
                if (context.Clients.Where(x => x.ClientId == client.ClientId).FirstOrDefault() == null)
                {
                    var newClient = new ClientEntity {
                        ClientId = client.ClientId, Client = client
                    };
                    newClient.AddDataToEntity();

                    context.Clients.Add(newClient);

                    context.SaveChanges();
                }
                else
                {
                    var newClient = context.Clients.Where(x => x.ClientId == client.ClientId).FirstOrDefault();
                    newClient.Client = client;

                    newClient.AddDataToEntity();

                    context.Clients.Update(newClient);

                    context.SaveChanges();
                }
            }

            Console.WriteLine("IdentityResources being populated");
            foreach (var resource in IdentityConfig.GetIdentityResources())
            {
                if (context.IdentityResources.Where(x => x.IdentityResourceName == resource.Name).FirstOrDefault() == null)
                {
                    var res = new IdentityResourceEntity {
                        IdentityResource = resource
                    };
                    res.AddDataToEntity();

                    context.IdentityResources.Add(res);

                    context.SaveChanges();
                }
                else
                {
                    var newres = context.IdentityResources.Where(x => x.IdentityResourceName == resource.Name).FirstOrDefault();
                    newres.IdentityResource = resource;

                    newres.AddDataToEntity();

                    context.IdentityResources.Update(newres);

                    context.SaveChanges();
                }
            }

            if (!context.ApiResources.Any())
            {
                Console.WriteLine("ApiResources being populated");
                foreach (var resource in IdentityConfig.GetApiResources())
                {
                    var api = new ApiResourceEntity {
                        ApiResource = resource
                    };
                    api.AddDataToEntity();

                    context.ApiResources.Add(api);
                }
                context.SaveChanges();
            }
            else
            {
                Console.WriteLine("ApiResources already populated");
            }

            Console.WriteLine("Done seeding database.");
            Console.WriteLine();
        }