if (BEARER.matcher(scheme).matches()) {
token = credentials;
}
} else {
next.handle(new YokeException(401, "Format is Authorization: Bearer [token]"));
return;
}
} else {
next.handle(new YokeException(401, "No Authorization header was found"));
return;
}
try {
final JsonObject jwtToken = jwt.decode(token);
final long now = System.currentTimeMillis();
if (jwtToken.containsField("iat")) {
Long iat = jwtToken.getLong("iat");
// issue at must be in the past
if (iat >= now) {
next.handle(new YokeException(401, "Invalid Token!"));
return;
}
}
if (jwtToken.containsField("nbf")) {
Long nbf = jwtToken.getLong("nbf");
// not before must be after now
if (nbf >= now) {
next.handle(new YokeException(401, "Invalid Token!"));
return;
}
}
if (jwtToken.containsField("exp")) {
Long exp = jwtToken.getLong("exp");
// expires must be after now
if (now > exp) {
next.handle(new YokeException(401, "Invalid Token!"));
return;
}
}
request.put("jwt", jwtToken);
if (handler == null) {
next.handle(null);
return;
}
handler.handle(jwtToken, next);
} catch (RuntimeException e) {
next.handle(new YokeException(401, e));
}
}