Search in sources :

Example 1 with ClientCredentialsProvider

use of org.keycloak.adapters.authentication.ClientCredentialsProvider in project keycloak by keycloak.

the class PreAuthActionsHandler method handleJwksRequest.

protected void handleJwksRequest() {
    try {
        JSONWebKeySet jwks = new JSONWebKeySet();
        ClientCredentialsProvider clientCredentialsProvider = deployment.getClientAuthenticator();
        // For now, just get signature key from JWT provider. We can add more if we support encryption etc.
        if (clientCredentialsProvider instanceof JWTClientCredentialsProvider) {
            PublicKey publicKey = ((JWTClientCredentialsProvider) clientCredentialsProvider).getPublicKey();
            JWK jwk = JWKBuilder.create().rs256(publicKey);
            jwks.setKeys(new JWK[] { jwk });
        } else {
            jwks.setKeys(new JWK[] {});
        }
        facade.getResponse().setStatus(200);
        facade.getResponse().setHeader("Content-Type", "application/json");
        JsonSerialization.writeValueToStream(facade.getResponse().getOutputStream(), jwks);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : JSONWebKeySet(org.keycloak.jose.jwk.JSONWebKeySet) PublicKey(java.security.PublicKey) JWTClientCredentialsProvider(org.keycloak.adapters.authentication.JWTClientCredentialsProvider) ClientCredentialsProvider(org.keycloak.adapters.authentication.ClientCredentialsProvider) VerificationException(org.keycloak.common.VerificationException) JWTClientCredentialsProvider(org.keycloak.adapters.authentication.JWTClientCredentialsProvider) JWK(org.keycloak.jose.jwk.JWK)

Aggregations

PublicKey (java.security.PublicKey)1 ClientCredentialsProvider (org.keycloak.adapters.authentication.ClientCredentialsProvider)1 JWTClientCredentialsProvider (org.keycloak.adapters.authentication.JWTClientCredentialsProvider)1 VerificationException (org.keycloak.common.VerificationException)1 JSONWebKeySet (org.keycloak.jose.jwk.JSONWebKeySet)1 JWK (org.keycloak.jose.jwk.JWK)1