Search in sources :

Example 1 with MACVerifier

use of com.nimbusds.jose.crypto.MACVerifier in project ratauth by alfa-laboratory.

the class HS256TokenProcessor method extractInfo.

@Override
@SneakyThrows
public Map<String, Object> extractInfo(String jwt, String secret) {
    SignedJWT signedJWT = SignedJWT.parse(jwt);
    final JWSVerifier verifier = new MACVerifier(Base64.getDecoder().decode(secret));
    if (!signedJWT.verify(verifier))
        throw new JWTVerificationException("User info extraction error");
    return signedJWT.getJWTClaimsSet().getClaims();
}
Also used : MACVerifier(com.nimbusds.jose.crypto.MACVerifier) JWSVerifier(com.nimbusds.jose.JWSVerifier) SignedJWT(com.nimbusds.jwt.SignedJWT) SneakyThrows(lombok.SneakyThrows)

Example 2 with MACVerifier

use of com.nimbusds.jose.crypto.MACVerifier in project gravitee-management-rest-api by gravitee-io.

the class ReferenceSerializer method deserialize.

public IdentityReference deserialize(String token) throws Exception {
    String sToken = new String(Base64.getDecoder().decode(token));
    // Parse the JWE string
    JWEObject jweObject = JWEObject.parse(sToken);
    // Decrypt with shared key
    jweObject.decrypt(new DirectDecrypter(secretKey.getEncoded()));
    // Extract payload
    SignedJWT signedJWT = jweObject.getPayload().toSignedJWT();
    // Check the HMAC
    signedJWT.verify(new MACVerifier(secretKey.getEncoded()));
    // Retrieve the JWT claims
    return new IdentityReference(signedJWT.getJWTClaimsSet().getIssuer(), signedJWT.getJWTClaimsSet().getSubject());
}
Also used : IdentityReference(io.gravitee.management.idp.api.identity.IdentityReference) MACVerifier(com.nimbusds.jose.crypto.MACVerifier) DirectDecrypter(com.nimbusds.jose.crypto.DirectDecrypter) SignedJWT(com.nimbusds.jwt.SignedJWT)

Aggregations

MACVerifier (com.nimbusds.jose.crypto.MACVerifier)2 SignedJWT (com.nimbusds.jwt.SignedJWT)2 JWSVerifier (com.nimbusds.jose.JWSVerifier)1 DirectDecrypter (com.nimbusds.jose.crypto.DirectDecrypter)1 IdentityReference (io.gravitee.management.idp.api.identity.IdentityReference)1 SneakyThrows (lombok.SneakyThrows)1