public static void UseIdentityAuthentication(this IAppBuilder app, Action <IdentityAuthenticationClientOptions> optionsAction)
        {
            var options = new IdentityAuthenticationClientOptions();

            optionsAction?.Invoke(options);

            app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions {
                Authority         = options.Authority,
                DelayLoadMetadata = true
            });
        }
        /// <summary>
        /// Registers the IdentityServer authentication handler.
        /// </summary>
        /// <param name="services">The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> to add the authentication handler to.</param>
        /// <param name="optionsAction">The configure options.</param>
        /// <returns></returns>
        public static void AddIdentityAuthentication(this IServiceCollection services, Action <IdentityAuthenticationClientOptions> optionsAction)
        {
            var options = new IdentityAuthenticationClientOptions();

            optionsAction?.Invoke(options);

            services
            .AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
            .AddIdentityServerAuthentication(optionsBuilder => {
                optionsBuilder.Authority            = options.Authority;
                optionsBuilder.ApiName              = options.ApiName;
                optionsBuilder.ApiSecret            = options.ApiSecret;
                optionsBuilder.RequireHttpsMetadata = false;
            });
        }