Search in sources :

Example 41 with Verification

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()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Job(com.auth0.json.mgmt.jobs.Job) Test(org.junit.Test)

Example 42 with Verification

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()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Job(com.auth0.json.mgmt.jobs.Job) Test(org.junit.Test)

Example 43 with Verification

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()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) EmailVerificationTicket(com.auth0.json.mgmt.tickets.EmailVerificationTicket) Test(org.junit.Test)

Example 44 with Verification

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());
}
Also used : Clock(com.auth0.jwt.interfaces.Clock) DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT) Date(java.util.Date) Test(org.junit.Test)

Example 45 with Verification

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);
    }
}
Also used : Verification(com.auth0.jwt.interfaces.Verification) DecodedJWT(com.auth0.jwt.interfaces.DecodedJWT)

Aggregations

Test (org.junit.Test)29 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)28 Algorithm (com.auth0.jwt.algorithms.Algorithm)14 JWTVerificationException (com.auth0.jwt.exceptions.JWTVerificationException)11 Date (java.util.Date)11 Verification (com.auth0.jwt.interfaces.Verification)9 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 JWTVerifier (com.auth0.jwt.JWTVerifier)5 RSAPublicKey (java.security.interfaces.RSAPublicKey)5 Job (com.auth0.json.mgmt.jobs.Job)4 Claim (com.auth0.jwt.interfaces.Claim)4 Clock (com.auth0.jwt.interfaces.Clock)4 List (java.util.List)4 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)4 JWT (com.auth0.jwt.JWT)3 JWTVerifier (com.auth0.jwt.interfaces.JWTVerifier)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 IOException (java.io.IOException)3 ByteBuffer (java.nio.ByteBuffer)3 FloodlightModuleException (net.floodlightcontroller.core.module.FloodlightModuleException)3