Search in sources :

Example 21 with Request

use of com.auth0.net.Request in project auth0-java by auth0.

the class GrantsEntity method delete.

/**
 * Delete an existing Grant. A token with scope delete:grants is needed.
 * See https://auth0.com/docs/api/management/v2#!/Grants/delete_grants_by_id<br>
 *
 * @param grantId The id of the grant to delete.
 * @return a Request to execute.
 */
public Request<Void> delete(String grantId) {
    Asserts.assertNotNull(grantId, "grant id");
    final String url = baseUrl.newBuilder().addPathSegments("api/v2/grants").addPathSegment(grantId).build().toString();
    VoidRequest request = new VoidRequest(client, url, "DELETE");
    request.addHeader("Authorization", "Bearer " + apiToken);
    return request;
}
Also used : VoidRequest(com.auth0.net.VoidRequest)

Example 22 with Request

use of com.auth0.net.Request in project auth0-java by auth0.

the class GrantsEntity method deleteAll.

/**
 * Deletes all Grants of a given user. A token with scope delete:grants is needed.
 * See https://auth0.com/docs/api/management/v2#!/Grants/delete_grants_by_id<br>
 *
 * @param userId The id of the user whose grants are deleted.
 * @return a Request to execute.
 */
public Request<Void> deleteAll(String userId) {
    Asserts.assertNotNull(userId, "user id");
    final String url = baseUrl.newBuilder().addPathSegments("api/v2/grants").addQueryParameter("user_id", userId).build().toString();
    VoidRequest request = new VoidRequest(client, url, "DELETE");
    request.addHeader("Authorization", "Bearer " + apiToken);
    return request;
}
Also used : VoidRequest(com.auth0.net.VoidRequest)

Example 23 with Request

use of com.auth0.net.Request in project auth0-java by auth0.

the class JobsEntityTest method shouldGetJobErrorDetails_noErrors.

@Test
public void shouldGetJobErrorDetails_noErrors() throws Exception {
    Request<List<JobErrorDetails>> request = api.jobs().getErrorDetails("1");
    assertThat(request, is(notNullValue()));
    server.noContentResponse();
    List<JobErrorDetails> response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/jobs/1/errors"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(response, is(notNullValue()));
    assertThat(response, is(empty()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) JobErrorDetails(com.auth0.json.mgmt.jobs.JobErrorDetails) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 24 with Request

use of com.auth0.net.Request in project auth0-java by auth0.

the class JobsEntityTest method shouldRequestUsersImport.

@Test
public void shouldRequestUsersImport() throws Exception {
    File usersFile = new File(MGMT_JOB_POST_USERS_IMPORTS_INPUT);
    Request<Job> request = api.jobs().importUsers("con_123456789", usersFile, null);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_JOB_POST_USERS_IMPORTS, 200);
    Job response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("POST", "/api/v2/jobs/users-imports"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    String ctHeader = recordedRequest.getHeader("Content-Type");
    assertThat(ctHeader, startsWith("multipart/form-data"));
    String[] ctParts = ctHeader.split("multipart/form-data; boundary=");
    RecordedMultipartRequest recordedMultipartRequest = new RecordedMultipartRequest(recordedRequest);
    assertThat(recordedMultipartRequest.getPartsCount(), is(2));
    assertThat(recordedMultipartRequest.getBoundary(), is(notNullValue()));
    assertThat(recordedMultipartRequest.getBoundary(), is(ctParts[1]));
    // Connection ID
    KeyValuePart formParam = recordedMultipartRequest.getKeyValuePart("connection_id");
    assertThat(formParam, is(notNullValue()));
    assertThat(formParam.getValue(), is("con_123456789"));
    // Users JSON
    FilePart jsonFile = recordedMultipartRequest.getFilePart("users");
    assertThat(jsonFile, is(notNullValue()));
    String utf8Contents = new String(Files.readAllBytes(usersFile.toPath()));
    assertThat(jsonFile.getContentType(), is("text/json"));
    assertThat(jsonFile.getFilename(), is("job_post_users_imports_input.json"));
    assertThat(jsonFile.getValue(), is(utf8Contents));
    assertThat(response, is(notNullValue()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) RecordedMultipartRequest(com.auth0.net.multipart.RecordedMultipartRequest) Job(com.auth0.json.mgmt.jobs.Job) File(java.io.File) KeyValuePart(com.auth0.net.multipart.KeyValuePart) FilePart(com.auth0.net.multipart.FilePart) Test(org.junit.Test)

Example 25 with Request

use of com.auth0.net.Request in project auth0-java by auth0.

the class JobsEntityTest method shouldSendUserVerificationEmailWithClientId.

@Test
public void shouldSendUserVerificationEmailWithClientId() throws Exception {
    Request<Job> request = api.jobs().sendVerificationEmail("google-oauth2|1234", "AaiyAPdpYdesoKnqjj8HJqRn4T5titww");
    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(2));
    assertThat(body, hasEntry("user_id", "google-oauth2|1234"));
    assertThat(body, hasEntry("client_id", "AaiyAPdpYdesoKnqjj8HJqRn4T5titww"));
    assertThat(response, is(notNullValue()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) Job(com.auth0.json.mgmt.jobs.Job) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)193 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)185 DecodedJWT (com.auth0.jwt.interfaces.DecodedJWT)77 IOException (java.io.IOException)76 List (java.util.List)63 Algorithm (com.auth0.jwt.algorithms.Algorithm)35 VoidRequest (com.auth0.net.VoidRequest)33 Auth0Exception (com.auth0.exception.Auth0Exception)30 APIException (com.auth0.exception.APIException)27 RateLimitException (com.auth0.exception.RateLimitException)25 HashMap (java.util.HashMap)24 PageFilter (com.auth0.client.mgmt.filter.PageFilter)23 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)23 ServletException (javax.servlet.ServletException)23 TokenHolder (com.auth0.json.auth.TokenHolder)22 JWTVerifier (com.auth0.jwt.JWTVerifier)22 ArrayList (java.util.ArrayList)22 Test (org.junit.jupiter.api.Test)22 JWTVerificationException (com.auth0.jwt.exceptions.JWTVerificationException)20 Date (java.util.Date)20