use of org.jose4j.jwt.consumer.JwtContext in project smallrye-jwt by smallrye.
the class DefaultJWTTokenParserTest method testParseMaxTimeToLiveNull.
@Test
public void testParseMaxTimeToLiveNull() throws Exception {
assertNull(config.getMaxTimeToLiveSecs());
JwtContext context = parser.parse(TokenUtils.signClaims("/Token1.json"), config);
assertNotNull(context);
}
use of org.jose4j.jwt.consumer.JwtContext in project wildfly-elytron by wildfly-security.
the class TokenValidator method parseAndVerifyToken.
/**
* Parse and verify the given ID token.
*
* @param idToken the ID token
* @return the {@code JwtContext} if the ID token was valid
* @throws OidcException if the ID token is invalid
*/
public VerifiedTokens parseAndVerifyToken(final String idToken, final String accessToken) throws OidcException {
try {
// first pass to determine the kid, if present
JwtConsumer firstPassJwtConsumer = new JwtConsumerBuilder().setSkipAllValidators().setDisableRequireSignature().setSkipSignatureVerification().build();
JwtContext idJwtContext = firstPassJwtConsumer.process(idToken);
String kid = idJwtContext.getJoseObjects().get(HEADER_INDEX).getKeyIdHeaderValue();
if (kid != null && clientConfiguration.getPublicKeyLocator() != null) {
jwtConsumerBuilder.setVerificationKey(clientConfiguration.getPublicKeyLocator().getPublicKey(kid, clientConfiguration));
} else {
// secret key
ClientSecretCredentialsProvider clientSecretCredentialsProvider = (ClientSecretCredentialsProvider) clientConfiguration.getClientAuthenticator();
jwtConsumerBuilder.setVerificationKey(clientSecretCredentialsProvider.getClientSecret());
}
jwtConsumerBuilder.registerValidator(new AtHashValidator(accessToken, clientConfiguration.getTokenSignatureAlgorithm()));
// second pass to validate
jwtConsumerBuilder.build().processContext(idJwtContext);
JwtClaims idJwtClaims = idJwtContext.getJwtClaims();
if (idJwtClaims == null) {
throw log.invalidIDTokenClaims();
}
JwtClaims jwtClaims = new JwtConsumerBuilder().setSkipSignatureVerification().setSkipAllValidators().build().processToClaims(accessToken);
return new VerifiedTokens(new IDToken(idJwtClaims), new AccessToken(jwtClaims));
} catch (InvalidJwtException e) {
throw log.invalidIDToken(e);
}
}
Aggregations