public static IAppBuilder UseIdentitiyServerJwt(this IAppBuilder app, JwtTokenValidationOptions options)
 {
     if (!string.IsNullOrWhiteSpace(options.Authority))
     {
         return app.UseDiscovery(options);
     }
     else
     {
         return app.ConfigureMiddleware(options.IssuerName, options.SigningCertificate, options.AuthenticationType);
     }
 }
        private static IAppBuilder UseDiscovery(this IAppBuilder app, JwtTokenValidationOptions options)
        {
            var authority = options.Authority;

            if (!authority.EndsWith("/"))
            {
                authority += "/";
            }

            authority += ".well-known/openid-configuration";
            var configuration = new ConfigurationManager<OpenIdConnectConfiguration>(authority);

            var result = configuration.GetConfigurationAsync().Result;
            var x5c = result.JsonWebKeySet.Keys.First().X5c.First();

            return app.ConfigureMiddleware(result.Issuer, new X509Certificate2(Convert.FromBase64String(x5c)), options.AuthenticationType);
        }