public static ClientCollection GetClientCollection(this IServiceCollection services)
        {
            IConfigurationSection section = SharedConfiguration.GetSection("OidcClients");
            IEnumerable <IConfigurationSection> clients = section.GetChildren();

            ClientCollection clientColl = new ClientCollection();
            bool             isSpa      = false;

            foreach (IConfigurationSection clientSection in clients)
            {
                isSpa = clientSection.GetValue <bool>("Spa");

                if (isSpa)
                {
                    clientColl.AddSPA(clientSection.Key, spa =>
                                      spa.WithLogoutRedirectUri(clientSection.GetValue <string>("LogoutUris")));

                    var scopes = clientSection.GetValue <string>("Scopes");
                    if (scopes != null && scopes.Length > 0)
                    {
                        clientColl[clientSection.Key].AllowedScopes = SharedConfiguration.GetStringCollection(clientSection, "Scopes");
                    }

                    var origins = clientSection.GetValue <string>("CorsOrigins");
                    if (origins != null && origins.Length > 0)
                    {
                        clientColl[clientSection.Key].AllowedCorsOrigins = SharedConfiguration.GetStringCollection(clientSection, "CorsOrigins");
                    }

                    clientColl[clientSection.Key].RedirectUris = SharedConfiguration.GetStringCollection(clientSection, "RedirectUris");
                }
                else
                {
                    clientColl.Add(new IdentityServer4.Models.Client
                    {
                        ClientId               = clientSection.Key,
                        AllowedGrantTypes      = SharedConfiguration.GetStringCollection(clientSection, "GrantTypes"),
                        AllowedScopes          = SharedConfiguration.GetStringCollection(clientSection, "Scopes"),
                        ClientSecrets          = GetSecretCollection(clientSection),
                        RequireConsent         = clientSection.GetValue <bool>("Consent"),
                        RequirePkce            = clientSection.GetValue <bool>("Pkce"),
                        RedirectUris           = SharedConfiguration.GetStringCollection(clientSection, "RedirectUris"),
                        PostLogoutRedirectUris = SharedConfiguration.GetStringCollection(clientSection, "LogoutUris"),
                        AllowedCorsOrigins     = SharedConfiguration.GetStringCollection(clientSection, "CorsOrigins"),
                    });
                }
            }

            return(clientColl);
        }