Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keycloak - Retrieve RSA public key

I have an app deployed with docker, one of the microservices is a jboss/keycloak server. Everything works fine, but keycloak RSA public key need to be retrieved manually. Is it possible to retrieve RSA public key through REST API?

like image 732
karjan Avatar asked Jul 14 '18 10:07

karjan


People also ask

Where is public key in Keycloak?

However, if I login to keycloak admin page and go into the realm settings-> keys and click the public key, a popup shows the public key minus the "-----BEGIN PUBLIC KEY-----" and "-----END PUBLIC KEY-----" headers and footers. Hard coding this enables everything to work.

How do I get a public realm key?

When admin rotates the realm keys in Keycloak admin console, the Client Adapter will be able to recognize it and automatically download new public key from Keycloak. However this automatic download of new keys is done just if you don't have realm-public-key option in your adapter with the hardcoded public key.


1 Answers

The url https://<keycloak-server>/auth/realms/<realm> contains a json response with the public key. This isn't advertised so it may change or go away. Using https://<keycloak-server>/auth/realms/<realm>/protocol/openid-connect/certs and setting up something to monitor the jwks response would be a much more maintainable way of handling it.

like image 181
Thomas Lann Avatar answered Oct 27 '22 19:10

Thomas Lann