use of com.auth0.jwt.interfaces.Verification in project auth0-java by auth0.
the class JobsEntityTest method shouldSendUserVerificationEmailWithOrgId.
@Test
public void shouldSendUserVerificationEmailWithOrgId() throws Exception {
Request<Job> request = api.jobs().sendVerificationEmail("google-oauth2|1234", "client_abc", null, "org_abc");
assertThat(request, is(notNullValue()));
server.jsonResponse(MGMT_JOB_POST_VERIFICATION_EMAIL, 200);
Job response = request.execute();
RecordedRequest recordedRequest = server.takeRequest();
assertThat(recordedRequest, hasMethodAndPath("POST", "/api/v2/jobs/verification-email"));
assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
Map<String, Object> body = bodyFromRequest(recordedRequest);
assertThat(body.size(), is(3));
assertThat(body, hasEntry("user_id", "google-oauth2|1234"));
assertThat(body, hasEntry("client_id", "client_abc"));
assertThat(body, hasEntry("organization_id", "org_abc"));
assertThat(response, is(notNullValue()));
}
use of com.auth0.jwt.interfaces.Verification in project auth0-java by auth0.
the class JobsEntityTest method shouldSendUserAVerificationEmailWithNullClientIdAndEmailVerification.
@Test
public void shouldSendUserAVerificationEmailWithNullClientIdAndEmailVerification() throws Exception {
Request<Job> request = api.jobs().sendVerificationEmail("google-oauth2|1234", null, null);
assertThat(request, is(notNullValue()));
server.jsonResponse(MGMT_JOB_POST_VERIFICATION_EMAIL, 200);
Job response = request.execute();
RecordedRequest recordedRequest = server.takeRequest();
assertThat(recordedRequest, hasMethodAndPath("POST", "/api/v2/jobs/verification-email"));
assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
Map<String, Object> body = bodyFromRequest(recordedRequest);
assertThat(body.size(), is(1));
assertThat(body, hasEntry("user_id", "google-oauth2|1234"));
assertThat(response, is(notNullValue()));
}
use of com.auth0.jwt.interfaces.Verification in project auth0-java by auth0.
the class TicketsEntityTest method shouldCreateEmailVerificationTicket.
@Test
public void shouldCreateEmailVerificationTicket() throws Exception {
EmailVerificationTicket ticket = new EmailVerificationTicket("uid123");
ticket.setIncludeEmailInRedirect(true);
ticket.setTTLSeconds(42);
Request<EmailVerificationTicket> request = api.tickets().requestEmailVerification(ticket);
assertThat(request, is(notNullValue()));
server.jsonResponse(MGMT_EMAIL_VERIFICATION_TICKET, 200);
EmailVerificationTicket response = request.execute();
RecordedRequest recordedRequest = server.takeRequest();
assertThat(recordedRequest, hasMethodAndPath("POST", "/api/v2/tickets/email-verification"));
assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
Map<String, Object> body = bodyFromRequest(recordedRequest);
assertThat(body.size(), is(3));
assertThat(body, hasEntry("user_id", "uid123"));
assertThat(body, hasEntry("includeEmailInRedirect", true));
assertThat(body, hasEntry("ttl_sec", 42));
assertThat(response, is(notNullValue()));
}
use of com.auth0.jwt.interfaces.Verification in project java-jwt by auth0.
the class JWTVerifierTest method shouldNotModifyOriginalClockDateWhenVerifying.
@Test
public void shouldNotModifyOriginalClockDateWhenVerifying() throws Exception {
Clock clock = mock(Clock.class);
Date clockDate = spy(new Date(DATE_TOKEN_MS_VALUE));
when(clock.getToday()).thenReturn(clockDate);
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0Nzc1OTJ9.isvT0Pqx0yjnZk53mUFSeYFJLDs-Ls9IsNAm86gIdZo";
JWTVerifier.BaseVerification verification = (JWTVerifier.BaseVerification) JWTVerifier.init(Algorithm.HMAC256("secret"));
JWTVerifier verifier = verification.build(clock);
DecodedJWT jwt = verifier.verify(token);
assertThat(jwt, is(notNullValue()));
verify(clockDate, never()).setTime(anyLong());
}
use of com.auth0.jwt.interfaces.Verification in project AuthGuard by AuthGuard.
the class AccessTokenProviderTest method verifyToken.
private void verifyToken(final String token, final String subject, final String jti, final List<String> permissions) {
final Verification verifier = JWT.require(JwtConfigParser.parseAlgorithm(ALGORITHM, null, KEY)).withIssuer(ISSUER).withSubject(subject);
if (jti != null) {
verifier.withJWTId(jti);
}
final DecodedJWT decodedJWT = verifier.build().verify(token);
if (permissions != null) {
assertThat(decodedJWT.getClaim("permissions").asArray(String.class)).hasSameSizeAs(permissions);
}
}
Aggregations