/// <summary>
        /// This method creates an Api Resource for Burst Chat api with the neccessary configuration.
        /// </summary>
        /// <param name="context">The configuration database context</param>
        /// <param name="configuration">The application settings configuration</param>
        public static void AddDevelopmentApiResource(ConfigurationDbContext?context, IdentitySecretsOptions identitySecretsOptions)
        {
            if (context == null)
            {
                return;
            }

            var creationDate = DateTime.Now;
            var apiName      = "burstchat.api";
            var apiSecret    = identitySecretsOptions
                               .ApiSecrets[apiName];

            var apiResource = new ApiResource
            {
                Created     = creationDate,
                Name        = apiName,
                Description = "The BurstChat API",
                Enabled     = true,
            };

            apiResource
            .Secrets = new List <ApiResourceSecret>
            {
                new()
                {
                    Value   = apiSecret.Sha256(),
                    Created = creationDate,
                }
            };

            apiResource
            .Scopes = new List <ApiResourceScope>
            {
                new()
                {
                    Scope = apiName,
                }
            };

            context
            .ApiResources
            .Add(apiResource);
        }
        /// <summary>
        /// This method creates a Client instance for the web application of BurstChat, with all
        /// the neccessary configuration.
        /// </summary>
        /// <param name="context">The configuration database context</param>
        /// <param name="configuration">The application settings configuration</param>
        private static void AddDevelopmentWebClient(ConfigurationDbContext?context, IdentitySecretsOptions identitySecretsOptions)
        {
            if (context == null)
            {
                return;
            }

            var creationDate    = DateTime.Now;
            var webClientId     = "burstchat.web.client";
            var webClientSecret = identitySecretsOptions
                                  .ClientSecrets[webClientId];

            var webClient = new Client
            {
                ClientName                  = "BurstChat Web Client",
                ClientId                    = webClientId,
                RequirePkce                 = false,
                AllowPlainTextPkce          = false,
                AllowAccessTokensViaBrowser = true,
                AllowRememberConsent        = true,
                AccessTokenType             = (int)AccessTokenType.Jwt,
                AllowOfflineAccess          = true,
                Created = creationDate
            };

            webClient
            .ClientSecrets = new List <ClientSecret>
            {
                new()
                {
                    Value       = webClientSecret.Sha256(),
                    Description = "The secret of the BurstChat Web Client",
                    Created     = creationDate
                }
            };

            webClient
            .AllowedScopes = new List <ClientScope>
            {
                new() { Scope = "openid" },
                new() { Scope = "profile" },
                new() { Scope = "burstchat.api" },
                new() { Scope = "burstchat.signal" },
                new() { Scope = "offline_access" }
            };

            webClient
            .AllowedCorsOrigins = new List <ClientCorsOrigin>
            {
                new ClientCorsOrigin {
                    Origin = "http://*****:*****@"http://localhost:4200/core/chat"
                }
            };

            webClient
            .PostLogoutRedirectUris = new List <ClientPostLogoutRedirectUri>
            {
                new ClientPostLogoutRedirectUri {
                    PostLogoutRedirectUri = @"http://localhost:4200/session/login"
                }
            };

            context
            .Clients
            .Add(webClient);
        }
        /// <summary>
        /// This method will make all the neccessary changes to the identity database contextes in order to
        /// ensure the existance of clients and api configuration.
        /// </summary>
        /// <param name="application">The application builder instance</param>
        /// <param name="secretsCallback">The callback that will populate the identity secrets options</param>
        public static void UseBurstChatDevelopmentResources(this IApplicationBuilder application, Action <IdentitySecretsOptions> secretsCallback)
        {
            var identitySecretsOptions = new IdentitySecretsOptions();

            secretsCallback(identitySecretsOptions);

            var serviceScopeFactory = application
                                      .ApplicationServices
                                      .GetService <IServiceScopeFactory>();

            using var serviceScope = serviceScopeFactory?.CreateScope();
            var creationDate = DateTime.Now;

            serviceScope?
            .ServiceProvider
            .GetRequiredService <PersistedGrantDbContext>()
            .Database
            .Migrate();

            var context = serviceScope?
                          .ServiceProvider
                          .GetRequiredService <ConfigurationDbContext>();

            context?.Database.Migrate();

            var clients = context?
                          .Clients
                          .ToList()
                          ?? Enumerable.Empty <Client>();

            var apis = context?
                       .ApiResources
                       .ToList()
                       ?? Enumerable.Empty <ApiResource>();

            var scopes = context?
                         .ApiScopes
                         .ToList()
                         ?? Enumerable.Empty <ApiScope>();

            var identities = context?
                             .IdentityResources
                             .ToList()
                             ?? Enumerable.Empty <IdentityResource>();

            foreach (var client in clients)
            {
                context?.Clients.Remove(client);
            }

            foreach (var api in apis)
            {
                context?.ApiResources.Remove(api);
            }

            foreach (var scope in scopes)
            {
                context?.ApiScopes.Remove(scope);
            }

            foreach (var identity in identities)
            {
                context?.IdentityResources.Remove(identity);
            }

            AddDevelopmentWebClient(context, identitySecretsOptions);
            AddDevelopmentApiResource(context, identitySecretsOptions);
            AddDevelopmentSignalResource(context, identitySecretsOptions);
            AddDevelopmeApiScopes(context);
            AddDevelopmentIdentityResources(context);

            context?.SaveChanges();
        }