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;
}
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;
}
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()));
}
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()));
}
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()));
}
Aggregations