use of org.jose4j.jwt.JwtClaims in project light-4j by networknt.
the class JwtVerifierTest method testVerifyJwt.
@Test
public void testVerifyJwt() throws Exception {
JwtClaims claims = ClaimsUtil.getTestClaims("steve", "EMPLOYEE", "f7d42348-c647-4efb-a52d-4c5787421e72", Arrays.asList("write:pets", "read:pets"), "user");
String jwt = JwtIssuer.getJwt(claims);
claims = null;
Assert.assertNotNull(jwt);
JwtVerifier jwtVerifier = new JwtVerifier(Config.getInstance().getJsonMapConfig(CONFIG_NAME));
try {
claims = jwtVerifier.verifyJwt(jwt, false, true);
} catch (Exception e) {
e.printStackTrace();
}
Assert.assertNotNull(claims);
Assert.assertEquals("steve", claims.getStringClaimValue(Constants.USER_ID_STRING));
try {
claims = jwtVerifier.verifyJwt(jwt, false, true);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("jwtClaims = " + claims);
}
use of org.jose4j.jwt.JwtClaims in project light-4j by networknt.
the class Http2ClientPoolIT method isTokenExpired.
private static boolean isTokenExpired(String authorization) {
boolean expired = false;
String jwt = getJwtFromAuthorization(authorization);
if (jwt != null) {
try {
JwtConsumer consumer = new JwtConsumerBuilder().setSkipAllValidators().setDisableRequireSignature().setSkipSignatureVerification().build();
JwtContext jwtContext = consumer.process(jwt);
JwtClaims jwtClaims = jwtContext.getJwtClaims();
try {
if ((NumericDate.now().getValue() - 60) >= jwtClaims.getExpirationTime().getValue()) {
expired = true;
}
} catch (MalformedClaimException e) {
logger.error("MalformedClaimException:", e);
}
} catch (InvalidJwtException e) {
e.printStackTrace();
}
}
return expired;
}
use of org.jose4j.jwt.JwtClaims in project light-4j by networknt.
the class Http2ClientPoolIT method getJwt.
private static String getJwt(int expiredInSeconds) throws Exception {
JwtClaims claims = getTestClaims();
claims.setExpirationTime(NumericDate.fromMilliseconds(System.currentTimeMillis() + expiredInSeconds * 1000));
return getJwt(claims);
}
use of org.jose4j.jwt.JwtClaims in project light-4j by networknt.
the class LightProxyHandler method extractClaimsFromJwt.
/**
* Takes in the header values from the request as a headerMap.
* Grab the JWT from the auth header, then extract and return the claims.
*
* @param headerValues - the header values from the request
* @return - the claims from the token
*/
private JwtClaims extractClaimsFromJwt(HeaderMap headerValues) {
// make sure request actually contained authentication header value
if (headerValues.get(Headers.AUTHORIZATION_STRING) != null) {
String jwt = String.valueOf(headerValues.get(Headers.AUTHORIZATION_STRING)).split(" ")[1];
JwtConsumer jwtConsumer = new JwtConsumerBuilder().setSkipSignatureVerification().setSkipAllDefaultValidators().setAllowedClockSkewInSeconds(LONG_CLOCK_SKEW).build();
JwtClaims jwtClaims = null;
try {
jwtClaims = jwtConsumer.processToClaims(jwt);
} catch (InvalidJwtException e) {
e.printStackTrace();
}
return jwtClaims;
} else {
return new JwtClaims();
}
}
use of org.jose4j.jwt.JwtClaims in project light-4j by networknt.
the class ClaimsUtil method getTestCcClaimsScopeScp.
public static JwtClaims getTestCcClaimsScopeScp(String clientId, String scope) {
JwtClaims claims = JwtIssuer.getDefaultJwtClaims();
claims.setClaim("client_id", clientId);
claims.setClaim("scp", scope);
return claims;
}
Aggregations