コード例 #1
0
        public IHttpActionResult GetKeyData()
        {
            Logger.Info("Start key discovery request");

            var webKeys = new List <JsonWebKeyDto>();

            foreach (var pubKey in _options.PublicKeysForMetadata)
            {
                if (pubKey != null)
                {
                    var cert64     = Convert.ToBase64String(pubKey.RawData);
                    var thumbprint = Base64Url.Encode(pubKey.GetCertHash());
                    var key        = pubKey.PublicKey.Key as RSACryptoServiceProvider;
                    var parameters = key.ExportParameters(false);
                    var exponent   = Base64Url.Encode(parameters.Exponent);
                    var modulus    = Base64Url.Encode(parameters.Modulus);

                    var webKey = new JsonWebKeyDto
                    {
                        kty = "RSA",
                        use = "sig",
                        kid = thumbprint,
                        x5t = thumbprint,
                        e   = exponent,
                        n   = modulus,
                        x5c = new[] { cert64 }
                    };

                    webKeys.Add(webKey);
                }
            }

            return(Json(new { keys = webKeys }));
        }
コード例 #2
0
        public async Task <IHttpActionResult> GetKeyData()
        {
            Logger.Info("Start key discovery request");

            if (_options.DiscoveryOptions.ShowKeySet == false)
            {
                Logger.Info("Key discovery disabled. 404.");
                return(NotFound());
            }

            var webKeys = new List <JsonWebKeyDto>();

            foreach (var pubKey in await _keyService.GetPublicKeysAsync())
            {
                if (pubKey != null)
                {
                    var webKey = new JsonWebKeyDto
                    {
                        kty = pubKey.Kty,
                        use = pubKey.Use,
                        kid = pubKey.Kid,
                        x5t = pubKey.X5t,
                        e   = pubKey.E,
                        n   = pubKey.N,
                        x5c = pubKey.X5c.ToArray()
                    };

                    webKeys.Add(webKey);
                }
            }

            return(Json(new { keys = webKeys }));
        }
コード例 #3
0
        public IHttpActionResult GetKeyData()
        {
            Logger.Info("Start key discovery request");

            if (!_options.DiscoveryEndpoint.IsEnabled)
            {
                Logger.Warn("Endpoint is disabled. Aborting");
                return(NotFound());
            }

            var webKeys = new List <JsonWebKeyDto>();

            foreach (var pubKey in _options.PublicKeysForMetadata)
            {
                if (pubKey != null)
                {
                    var cert64     = Convert.ToBase64String(pubKey.RawData);
                    var thumbprint = Base64Url.Encode(pubKey.GetCertHash());

                    var webKey = new JsonWebKeyDto
                    {
                        kty = "RSA",
                        use = "sig",
                        kid = thumbprint,
                        x5t = thumbprint,
                        x5c = new[] { cert64 }
                    };

                    webKeys.Add(webKey);
                }
            }

            return(Json(new { keys = webKeys }));
        }
        protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
        {
            if (request.RequestUri.AbsoluteUri.EndsWith("openid-configuration"))
            {
                var data = new Dictionary<object, object>
                {
                    { "issuer", _issuerName },
                    { "jwks_uri", "https://discodoc/jwks" }
                };

                var response = new HttpResponseMessage(HttpStatusCode.OK);
                response.Content = new ObjectContent<Dictionary<object, object>>(data, new JsonMediaTypeFormatter());

                return Task.FromResult(response);
            }

            if (request.RequestUri.AbsoluteUri.EndsWith("jwks"))
            {
                var webKeys = new List<JsonWebKeyDto>();

                var cert64 = Convert.ToBase64String(_signingCertificate.RawData);
                var thumbprint = Base64Url.Encode(_signingCertificate.GetCertHash());
                var key = _signingCertificate.PublicKey.Key as RSACryptoServiceProvider;
                var parameters = key.ExportParameters(false);
                var exponent = Base64Url.Encode(parameters.Exponent);
                var modulus = Base64Url.Encode(parameters.Modulus);

                var webKey = new JsonWebKeyDto
                {
                    kty = "RSA",
                    use = "sig",
                    kid = thumbprint,
                    x5t = thumbprint,
                    e = exponent,
                    n = modulus,
                    x5c = new[] { cert64 }
                };

                webKeys.Add(webKey);

                var data = new Dictionary<object, object>
                {
                    { "keys", webKeys }
                };

                var response = new HttpResponseMessage(HttpStatusCode.OK);
                response.Content = new ObjectContent<Dictionary<object, object>>(data, new JsonMediaTypeFormatter());

                return Task.FromResult(response);
            }

            return Task.FromResult(new HttpResponseMessage(HttpStatusCode.NotFound));
        }
コード例 #5
0
        protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
        {
            if (request.RequestUri.AbsoluteUri.EndsWith("openid-configuration"))
            {
                var data = new Dictionary <object, object>
                {
                    { "issuer", _issuerName },
                    { "jwks_uri", "https://discodoc/jwks" }
                };

                var response = new HttpResponseMessage(HttpStatusCode.OK);
                response.Content = new ObjectContent <Dictionary <object, object> >(data, new JsonMediaTypeFormatter());

                return(Task.FromResult(response));
            }

            if (request.RequestUri.AbsoluteUri.EndsWith("jwks"))
            {
                var webKeys = new List <JsonWebKeyDto>();

                var cert64     = Convert.ToBase64String(_signingCertificate.RawData);
                var thumbprint = Base64Url.Encode(_signingCertificate.GetCertHash());
                var key        = _signingCertificate.PublicKey.Key as RSACryptoServiceProvider;
                var parameters = key.ExportParameters(false);
                var exponent   = Base64Url.Encode(parameters.Exponent);
                var modulus    = Base64Url.Encode(parameters.Modulus);

                var webKey = new JsonWebKeyDto
                {
                    kty = "RSA",
                    use = "sig",
                    kid = thumbprint,
                    x5t = thumbprint,
                    e   = exponent,
                    n   = modulus,
                    x5c = new[] { cert64 }
                };

                webKeys.Add(webKey);

                var data = new Dictionary <object, object>
                {
                    { "keys", webKeys }
                };

                var response = new HttpResponseMessage(HttpStatusCode.OK);
                response.Content = new ObjectContent <Dictionary <object, object> >(data, new JsonMediaTypeFormatter());

                return(Task.FromResult(response));
            }

            return(Task.FromResult(new HttpResponseMessage(HttpStatusCode.NotFound)));
        }
コード例 #6
0
        public async Task <IHttpActionResult> GetKeyData()
        {
            Logger.Info("Start key discovery request");

            if (_options.DiscoveryOptions.ShowKeySet == false)
            {
                Logger.Info("Key discovery disabled. 404.");
                return(NotFound());
            }

            var webKeys = new List <JsonWebKeyDto>();

            foreach (var pubKey in await _keyService.GetPublicKeysAsync())
            {
                if (pubKey != null)
                {
                    var cert64     = Convert.ToBase64String(pubKey.RawData);
                    var thumbprint = Base64Url.Encode(pubKey.GetCertHash());
                    var key        = pubKey.PublicKey.Key as RSACryptoServiceProvider;
                    var parameters = key.ExportParameters(false);
                    var exponent   = Base64Url.Encode(parameters.Exponent);
                    var modulus    = Base64Url.Encode(parameters.Modulus);

                    var webKey = new JsonWebKeyDto
                    {
                        kty = "RSA",
                        use = "sig",
                        kid = await _keyService.GetKidAsync(pubKey),
                        x5t = thumbprint,
                        e   = exponent,
                        n   = modulus,
                        x5c = new[] { cert64 }
                    };

                    webKeys.Add(webKey);
                }
            }

            return(Json(new { keys = webKeys }));
        }
コード例 #7
0
        public async Task<IHttpActionResult> GetKeyData()
        {
            Logger.Info("Start key discovery request");

            if (_options.DiscoveryOptions.ShowKeySet == false)
            {
                Logger.Info("Key discovery disabled. 404.");
                return NotFound();
            }

            var webKeys = new List<JsonWebKeyDto>();
            foreach (var pubKey in await _keyService.GetPublicKeysAsync())
            {
                if (pubKey != null)
                {
                    var cert64 = Convert.ToBase64String(pubKey.RawData);
                    var thumbprint = Base64Url.Encode(pubKey.GetCertHash());
                    var key = pubKey.PublicKey.Key as RSACryptoServiceProvider;
                    var parameters = key.ExportParameters(false);
                    var exponent = Base64Url.Encode(parameters.Exponent);
                    var modulus = Base64Url.Encode(parameters.Modulus);

                    var webKey = new JsonWebKeyDto
                    {
                        kty = "RSA",
                        use = "sig",
                        kid = await _keyService.GetKidAsync(pubKey),
                        x5t = thumbprint,
                        e = exponent,
                        n = modulus,
                        x5c = new[] { cert64 }
                    };

                    webKeys.Add(webKey);
                }
            }

            return Json(new { keys = webKeys });
        }
        public IHttpActionResult GetKeyData()
        {
            Logger.Info("Start key discovery request");

            if (!_options.Endpoints.DiscoveryEndpoint.IsEnabled)
            {
                Logger.Warn("Endpoint is disabled. Aborting");
                return NotFound();
            }

            var webKeys = new List<JsonWebKeyDto>();
            foreach (var pubKey in _options.PublicKeysForMetadata)
            {
                if (pubKey != null)
                {
                    var cert64 = Convert.ToBase64String(pubKey.RawData);
                    var thumbprint = Base64Url.Encode(pubKey.GetCertHash());
                    var key = pubKey.PublicKey.Key as RSACryptoServiceProvider;
                    var parameters = key.ExportParameters(false);
                    var exponent = Convert.ToBase64String(parameters.Exponent);
                    var modulus = Convert.ToBase64String(parameters.Modulus);

                    var webKey = new JsonWebKeyDto
                    {
                        kty = "RSA",
                        use = "sig",
                        kid = thumbprint,
                        x5t = thumbprint,
                        e = exponent,
                        n = modulus,
                        x5c = new[] { cert64 }
                    };

                    webKeys.Add(webKey);
                }
            }

            return Json(new { keys = webKeys });
        }
        public IHttpActionResult GetKeyData()
        {
            Logger.Info("Start key discovery request");

            if (!_settings.DiscoveryEndpoint.IsEnabled)
            {
                Logger.Warn("Endpoint is disabled. Aborting");
                return NotFound();
            }

            var webKeys = new List<JsonWebKeyDto>();
            foreach (var pubKey in _settings.PublicKeysForMetadata)
            {
                if (pubKey != null)
                {
                    var cert64 = Convert.ToBase64String(pubKey.RawData);
                    var thumbprint = Base64Url.Encode(pubKey.GetCertHash());

                    var webKey = new JsonWebKeyDto
                    {
                        kty = "RSA",
                        use = "sig",
                        kid = thumbprint,
                        x5t = thumbprint,
                        x5c = new string[] { cert64 }
                    };

                    webKeys.Add(webKey);
                }
            }

            return Json(new { keys = webKeys });
        }