Exemplo n.º 1
0
        /// <summary>
        /// Define trusted Client client
        /// </summary>
        /// <returns></returns>
        public static IEnumerable <Client> GetClients(IConfigurationSection section)
        {
            List <Client> clients = new List <Client>();

            if (section != null)
            {
                List <ClientConfig> configs = new List <ClientConfig>();
                section.Bind("Clients", configs);
                foreach (var config in configs)
                {
                    Client client = new Client();
                    client.ClientId = config.ClientId;
                    List <Secret> clientSecrets = new List <Secret>();
                    foreach (var secret in config.ClientSecrets)
                    {
                        clientSecrets.Add(new Secret(secret.Sha256()));
                    }
                    client.ClientSecrets = clientSecrets.ToArray();

                    GrantTypes grantTypes        = new GrantTypes();
                    var        allowedGrantTypes = grantTypes.GetType().GetProperty(config.AllowedGrantTypes);
                    client.AllowedGrantTypes = allowedGrantTypes == null ?
                                               GrantTypes.ClientCredentials : (ICollection <string>)allowedGrantTypes.GetValue(grantTypes, null);

                    client.AllowedScopes = config.AllowedScopes.ToArray();

                    clients.Add(client);
                }
            }
            return(clients.ToArray());
        }
Exemplo n.º 2
0
        public static IEnumerable <Client> GetClients(IConfigurationSection section)
        {
            var clients = new List <Client>();
            List <ClientConfig> configs = new List <ClientConfig>();

            section.Bind("Clients", configs);
            foreach (var config in configs)
            {
                Client client = new Client();
                client.ClientId = config.ClientId;
                List <Secret> clientSecrets = new List <Secret>();
                foreach (var secret in config.ClientSecrets)
                {
                    clientSecrets.Add(new Secret(secret.Sha256()));
                }
                client.ClientSecrets = clientSecrets.ToArray();
                GrantTypes grantTypes        = new GrantTypes();
                var        allowedGrantTypes = grantTypes.GetType().GetProperty(config.AllowedGrantTypes);
                client.AllowedGrantTypes = allowedGrantTypes == null ?
                                           GrantTypes.ClientCredentials : (ICollection <string>)allowedGrantTypes.GetValue(grantTypes, null);

                client.AllowedScopes.Add(IdentityServerConstants.StandardScopes.OpenId);
                client.AllowedScopes.Add(IdentityServerConstants.StandardScopes.Profile);
                config.AllowedScopes?.Any(a => { client.AllowedScopes.Add(a); return(false); });

                clients.Add(client);
            }
            return(clients);
        }