use of com.auth0.jwt.Claim in project chemvantage by chuckwight.
the class LTIv1p3Launch method ltiv1p3LaunchRequest.
void ltiv1p3LaunchRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
// StringBuffer debug = new StringBuffer();
// ensures proper OIDC authorization flow completed
JsonObject state = validateStateToken(request);
// returns the validated Deployment
Deployment d = validateIdToken(request);
// Decode the JWT id_token payload as a JsonObject:
JsonObject claims = null;
try {
DecodedJWT id_token = JWT.decode(request.getParameter("id_token"));
String json = new String(Base64.getUrlDecoder().decode(id_token.getPayload()));
claims = JsonParser.parseString(json).getAsJsonObject();
} catch (Exception e) {
throw new Exception("id_token was not a valid JWT.");
}
// verify that the redirect_uri are consistent with the state token:
if (!state.get("redirect_uri").getAsString().contains("https://" + request.getServerName() + "/lti/launch"))
throw new Exception("Invalid redirect_uri.");
// required
verifyLtiMessageClaims(claims);
User user = getUserClaims(claims);
switch(claims.get("https://purl.imsglobal.org/spec/lti/claim/message_type").getAsString()) {
case "LtiResourceLinkRequest":
launchResourceLink(request, response, d, user, claims);
break;
case "LtiSubmissionReviewRequest":
launchSubmissionReview(response, claims, d, user);
break;
}
}
use of com.auth0.jwt.Claim in project java-jwt by auth0.
the class PayloadDeserializer method getDateFromSeconds.
Date getDateFromSeconds(Map<String, JsonNode> tree, String claimName) {
JsonNode node = tree.get(claimName);
if (node == null || node.isNull()) {
return null;
}
if (!node.canConvertToLong()) {
throw new JWTDecodeException(String.format("The claim '%s' contained a non-numeric date value.", claimName));
}
final long ms = node.asLong() * 1000;
return new Date(ms);
}
use of com.auth0.jwt.Claim in project supertokens-core by supertokens.
the class JWTCreateTest method testThatDecodedJWTUsesCustomIssuer.
/**
* Test that final JWT uses custom iss claim instead of jwks domain
*/
@Test
public void testThatDecodedJWTUsesCustomIssuer() throws Exception {
String[] args = { "../" };
TestingProcessManager.TestingProcess process = TestingProcessManager.start(args);
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED));
String algorithm = "RS256";
JsonObject payload = new JsonObject();
payload.addProperty("iss", "http://customiss");
String jwksDomain = "http://localhost";
long validity = 3600;
String jwt = JWTSigningFunctions.createJWTToken(process.getProcess(), algorithm, payload, jwksDomain, validity);
DecodedJWT decodedJWT = JWT.decode(jwt);
String issuer = decodedJWT.getIssuer();
if (!issuer.equals("http://customiss")) {
throw new Exception("Decoded JWT does not contain 'iss' claim matching user defined value");
}
process.kill();
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED));
}
use of com.auth0.jwt.Claim in project supertokens-core by supertokens.
the class JWTCreateTest method testThatDecodedJWTHasAValidHeader.
/**
* Verify that the JWT header has the required properties and that the values are valid
*/
@Test
public void testThatDecodedJWTHasAValidHeader() throws Exception {
String[] args = { "../" };
TestingProcessManager.TestingProcess process = TestingProcessManager.start(args);
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED));
String algorithm = "RS256";
JsonObject payload = new JsonObject();
payload.addProperty("customClaim", "customValue");
String jwksDomain = "http://localhost";
long validity = 3600;
String jwt = JWTSigningFunctions.createJWTToken(process.getProcess(), algorithm, payload, jwksDomain, validity);
DecodedJWT decodedJWT = JWT.decode(jwt);
Claim headerAlg = decodedJWT.getHeaderClaim("alg");
Claim headerType = decodedJWT.getHeaderClaim("typ");
Claim headerKeyId = decodedJWT.getHeaderClaim("kid");
if (headerAlg.isNull() || headerType.isNull() || headerKeyId.isNull()) {
throw new Exception("JWT header is missing one or more required claim (alg, typ, kid)");
}
if (!headerAlg.asString().equals(algorithm)) {
throw new Exception("Algorithm in JWT header does not match algorithm passed to JWTSigningFunctions.createJWTToken");
}
if (!headerType.asString().equals("JWT")) {
throw new Exception("JWT header contains wrong type: Expected: JWT, Actual: " + headerType.asString());
}
if (headerKeyId.asString().isEmpty()) {
throw new Exception("Value for kid in JWT header is invalid");
}
process.kill();
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED));
}
use of com.auth0.jwt.Claim in project supertokens-core by supertokens.
the class JWTSigningAPITest2_9 method testThatDecodedJWTHasCustomPayload.
/**
* Test that the returned JWT payload contains provided custom payload properties
*/
@Test
public void testThatDecodedJWTHasCustomPayload() throws Exception {
String[] args = { "../" };
TestingProcessManager.TestingProcess process = TestingProcessManager.start(args);
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STARTED));
JsonObject requestBody = new JsonObject();
requestBody.addProperty("algorithm", "rs256");
requestBody.addProperty("jwksDomain", "http://localhost");
JsonObject customPayload = new JsonObject();
customPayload.addProperty("customClaim", "customValue");
requestBody.add("payload", customPayload);
requestBody.addProperty("validity", 3600);
JsonObject response = HttpRequestForTesting.sendJsonPOSTRequest(process.getProcess(), "", "http://localhost:3567/recipe/jwt", requestBody, 1000, 1000, null, Utils.getCdiVersion2_9ForTests(), "jwt");
String jwt = response.get("jwt").getAsString();
DecodedJWT decodedJWT = JWT.decode(jwt);
Claim customClaim = decodedJWT.getClaim("customClaim");
assertTrue(!customClaim.isNull() && customClaim.asString().equals("customValue"));
process.kill();
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED));
}
Aggregations