use of org.jose4j.jwt.JwtClaims in project light-4j by networknt.
the class Http2ClientPoolTest 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 Http2ClientPoolTest method getTestClaims.
private static JwtClaims getTestClaims() {
JwtClaims claims = new JwtClaims();
claims.setIssuer("urn:com:networknt:oauth2:v1");
claims.setAudience("urn:com.networknt");
claims.setExpirationTimeMinutesInTheFuture(10);
// a unique identifier for the token
claims.setGeneratedJwtId();
// when the token was issued/created (now)
claims.setIssuedAtToNow();
// time before which the token is not yet valid (2 minutes ago)
claims.setNotBeforeMinutesInThePast(2);
claims.setClaim("version", "1.0");
claims.setClaim("user_id", "steve");
claims.setClaim("user_type", "EMPLOYEE");
claims.setClaim("client_id", "aaaaaaaa-1234-1234-1234-bbbbbbbb");
List<String> scope = Arrays.asList("api.r", "api.w");
// multi-valued claims work too and will end up as a JSON array
claims.setStringListClaim("scope", scope);
return claims;
}
use of org.jose4j.jwt.JwtClaims in project light-4j by networknt.
the class Http2ClientTest method getTestClaims.
private static JwtClaims getTestClaims() {
JwtClaims claims = new JwtClaims();
claims.setIssuer("urn:com:networknt:oauth2:v1");
claims.setAudience("urn:com.networknt");
claims.setExpirationTimeMinutesInTheFuture(10);
// a unique identifier for the token
claims.setGeneratedJwtId();
// when the token was issued/created (now)
claims.setIssuedAtToNow();
// time before which the token is not yet valid (2 minutes ago)
claims.setNotBeforeMinutesInThePast(2);
claims.setClaim("version", "1.0");
claims.setClaim("user_id", "steve");
claims.setClaim("user_type", "EMPLOYEE");
claims.setClaim("client_id", "aaaaaaaa-1234-1234-1234-bbbbbbbb");
List<String> scope = Arrays.asList("api.r", "api.w");
// multi-valued claims work too and will end up as a JSON array
claims.setStringListClaim("scope", scope);
return claims;
}
use of org.jose4j.jwt.JwtClaims in project light-4j by networknt.
the class Http2ClientTest 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 Http2ClientIT method getTestClaims.
private static JwtClaims getTestClaims() {
JwtClaims claims = new JwtClaims();
claims.setIssuer("urn:com:networknt:oauth2:v1");
claims.setAudience("urn:com.networknt");
claims.setExpirationTimeMinutesInTheFuture(10);
// a unique identifier for the token
claims.setGeneratedJwtId();
// when the token was issued/created (now)
claims.setIssuedAtToNow();
// time before which the token is not yet valid (2 minutes ago)
claims.setNotBeforeMinutesInThePast(2);
claims.setClaim("version", "1.0");
claims.setClaim("user_id", "steve");
claims.setClaim("user_type", "EMPLOYEE");
claims.setClaim("client_id", "aaaaaaaa-1234-1234-1234-bbbbbbbb");
List<String> scope = Arrays.asList("api.r", "api.w");
// multi-valued claims work too and will end up as a JSON array
claims.setStringListClaim("scope", scope);
return claims;
}
Aggregations