use of org.keycloak.jose.jws.JWSBuilder in project keycloak by keycloak.
the class ClientAuthSignedJWTTest method createSignledRequestToken.
private String createSignledRequestToken(PrivateKey privateKey, PublicKey publicKey, String algorithm, JsonWebToken jwt) {
String kid = KeyUtils.createKeyId(publicKey);
SignatureSignerContext signer = oauth.createSigner(privateKey, kid, algorithm);
String ret = new JWSBuilder().kid(kid).jsonContent(jwt).sign(signer);
return ret;
}
use of org.keycloak.jose.jws.JWSBuilder in project keycloak by keycloak.
the class AuthUtil method getSignedRequestToken.
public static String getSignedRequestToken(String keystore, String storePass, String keyPass, String alias, int sigLifetime, String clientId, String realmInfoUrl) {
KeyPair keypair = KeystoreUtil.loadKeyPairFromKeystore(keystore, storePass, keyPass, alias, KeystoreUtil.KeystoreFormat.JKS);
JsonWebToken reqToken = new JsonWebToken();
reqToken.id(UUID.randomUUID().toString());
reqToken.issuer(clientId);
reqToken.subject(clientId);
reqToken.audience(realmInfoUrl);
int now = Time.currentTime();
reqToken.issuedAt(now);
reqToken.expiration(now + sigLifetime);
reqToken.notBefore(now);
String signedRequestToken = new JWSBuilder().jsonContent(reqToken).rsa256(keypair.getPrivate());
return signedRequestToken;
}
use of org.keycloak.jose.jws.JWSBuilder in project keycloak by keycloak.
the class ClientRegistrationTokenUtils method updateTokenSignature.
public static String updateTokenSignature(KeycloakSession session, ClientRegistrationAuth auth) {
String algorithm = session.tokens().signatureAlgorithm(TokenCategory.INTERNAL);
SignatureSignerContext signer = session.getProvider(SignatureProvider.class, algorithm).signer();
if (signer.getKid().equals(auth.getKid())) {
return auth.getToken();
} else {
RegistrationAccessToken regToken = new RegistrationAccessToken();
regToken.setRegistrationAuth(auth.getRegistrationAuth().toString().toLowerCase());
regToken.type(auth.getJwt().getType());
regToken.id(auth.getJwt().getId());
regToken.issuedAt(Time.currentTime());
regToken.expiration(0);
regToken.issuer(auth.getJwt().getIssuer());
regToken.audience(auth.getJwt().getIssuer());
String token = new JWSBuilder().jsonContent(regToken).sign(signer);
return token;
}
}
Aggregations