Search in sources :

Example 6 with JWK

use of org.keycloak.jose.jwk.JWK in project keycloak by keycloak.

the class OAuthClient method findKey.

private KeyWrapper findKey(JSONWebKeySet jsonWebKeySet, String algoritm, String kid) {
    for (JWK k : jsonWebKeySet.getKeys()) {
        if (k.getKeyId().equals(kid) && k.getAlgorithm().equals(algoritm)) {
            PublicKey publicKey = JWKParser.create(k).toPublicKey();
            KeyWrapper key = new KeyWrapper();
            key.setKid(k.getKeyId());
            key.setAlgorithm(k.getAlgorithm());
            key.setPublicKey(publicKey);
            key.setUse(KeyUse.SIG);
            return key;
        }
    }
    return null;
}
Also used : KeyWrapper(org.keycloak.crypto.KeyWrapper) PublicKey(java.security.PublicKey) JWK(org.keycloak.jose.jwk.JWK)

Aggregations

JWK (org.keycloak.jose.jwk.JWK)6 JSONWebKeySet (org.keycloak.jose.jwk.JSONWebKeySet)5 PublicKey (java.security.PublicKey)4 IOException (java.io.IOException)2 X509Certificate (java.security.cert.X509Certificate)2 List (java.util.List)2 GET (javax.ws.rs.GET)2 NotFoundException (javax.ws.rs.NotFoundException)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 NoCache (org.jboss.resteasy.annotations.cache.NoCache)2 KeyUse (org.keycloak.crypto.KeyUse)2 CertificateRepresentation (org.keycloak.representations.idm.CertificateRepresentation)2 InputStream (java.io.InputStream)1 KeyPair (java.security.KeyPair)1 KeyStore (java.security.KeyStore)1 PrivateKey (java.security.PrivateKey)1 Collections (java.util.Collections)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1