public void testJWT()
throws Exception {
UserInfo claims = new UserInfo(new Subject("alice"));
claims.setName("Alice Adams");
claims.setEmail(new InternetAddress("alice@wonderland.net"));
claims.setEmailVerified(true);
JWTClaimsSet claimsSet = claims.toJWTClaimsSet();
Secret secret = new Secret();
SignedJWT jwt = new SignedJWT(new JWSHeader(JWSAlgorithm.HS256), claimsSet);
jwt.sign(new MACSigner(secret.getValueBytes()));
UserInfoSuccessResponse response = new UserInfoSuccessResponse(jwt);
assertEquals(jwt, response.getUserInfoJWT());
assertEquals("application/jwt; charset=UTF-8", response.getContentType().toString());
assertNull(response.getUserInfo());
HTTPResponse httpResponse = response.toHTTPResponse();
response = UserInfoSuccessResponse.parse(httpResponse);
assertEquals("application/jwt; charset=UTF-8", response.getContentType().toString());
assertNull(response.getUserInfo());
jwt = (SignedJWT)response.getUserInfoJWT();
assertTrue(jwt.getState().equals(JWSObject.State.SIGNED));
claims = new UserInfo(response.getUserInfoJWT().getJWTClaimsSet().toJSONObject());
assertEquals("alice", claims.getSubject().getValue());
assertEquals("Alice Adams", claims.getName());
assertEquals("alice@wonderland.net", claims.getEmail().toString());
assertTrue(claims.getEmailVerified());
}