Search in sources :

Example 6 with Job

use of com.auth0.json.mgmt.jobs.Job in project engine by Lumeer.

the class UserAuth0Utils method resendVerificationEmail.

public void resendVerificationEmail(final String authId) throws Auth0Exception {
    if (!initialized) {
        init();
    }
    if (!skipSecurity) {
        refreshManagementApiToken();
        final ManagementAPI mApi = new ManagementAPI(domain, managementApiToken);
        Job job = mApi.jobs().sendVerificationEmail(authId, backendClientId).execute();
    }
}
Also used : ManagementAPI(com.auth0.client.mgmt.ManagementAPI) Job(com.auth0.json.mgmt.jobs.Job)

Example 7 with Job

use of com.auth0.json.mgmt.jobs.Job in project auth0-java by auth0.

the class JobsEntityTest method shouldRequestUsersImportWithOptions.

@Test
public void shouldRequestUsersImportWithOptions() throws Exception {
    UsersImportOptions options = new UsersImportOptions();
    options.withExternalId("ext_id123");
    options.withUpsert(true);
    options.withSendCompletionEmail(false);
    File usersFile = new File(MGMT_JOB_POST_USERS_IMPORTS_INPUT);
    Request<Job> request = api.jobs().importUsers("con_123456789", usersFile, options);
    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(5));
    assertThat(recordedMultipartRequest.getBoundary(), is(notNullValue()));
    assertThat(recordedMultipartRequest.getBoundary(), is(ctParts[1]));
    // Connection ID
    KeyValuePart connectionIdParam = recordedMultipartRequest.getKeyValuePart("connection_id");
    assertThat(connectionIdParam, is(notNullValue()));
    assertThat(connectionIdParam.getValue(), is("con_123456789"));
    // External ID
    KeyValuePart externalIdParam = recordedMultipartRequest.getKeyValuePart("external_id");
    assertThat(externalIdParam, is(notNullValue()));
    assertThat(externalIdParam.getValue(), is("ext_id123"));
    // Upsert
    KeyValuePart upsertParam = recordedMultipartRequest.getKeyValuePart("upsert");
    assertThat(upsertParam, is(notNullValue()));
    assertThat(upsertParam.getValue(), is("true"));
    // Send Completion Email
    KeyValuePart sendCompletionEmailParam = recordedMultipartRequest.getKeyValuePart("send_completion_email");
    assertThat(sendCompletionEmailParam, is(notNullValue()));
    assertThat(sendCompletionEmailParam.getValue(), is("false"));
    // 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) UsersImportOptions(com.auth0.client.mgmt.filter.UsersImportOptions) 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 8 with Job

use of com.auth0.json.mgmt.jobs.Job in project auth0-java by auth0.

the class JobsEntityTest method shouldSendUserVerificationEmailWithIdentity.

@Test
public void shouldSendUserVerificationEmailWithIdentity() throws Exception {
    EmailVerificationIdentity identity = new EmailVerificationIdentity("google-oauth2", "1234");
    Request<Job> request = api.jobs().sendVerificationEmail("google-oauth2|1234", "AaiyAPdpYdesoKnqjj8HJqRn4T5titww", identity);
    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", "AaiyAPdpYdesoKnqjj8HJqRn4T5titww"));
    Map<String, String> identityMap = new HashMap<>();
    identityMap.put("provider", "google-oauth2");
    identityMap.put("user_id", "1234");
    assertThat(body, hasEntry("identity", identityMap));
    assertThat(response, is(notNullValue()));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) HashMap(java.util.HashMap) Job(com.auth0.json.mgmt.jobs.Job) EmailVerificationIdentity(com.auth0.json.mgmt.EmailVerificationIdentity) Test(org.junit.Test)

Example 9 with Job

use of com.auth0.json.mgmt.jobs.Job 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 10 with Job

use of com.auth0.json.mgmt.jobs.Job 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)

Aggregations

Job (com.auth0.json.mgmt.jobs.Job)12 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)11 Test (org.junit.Test)11 UsersExportFilter (com.auth0.client.mgmt.filter.UsersExportFilter)3 FilePart (com.auth0.net.multipart.FilePart)2 KeyValuePart (com.auth0.net.multipart.KeyValuePart)2 RecordedMultipartRequest (com.auth0.net.multipart.RecordedMultipartRequest)2 File (java.io.File)2 HashMap (java.util.HashMap)2 ManagementAPI (com.auth0.client.mgmt.ManagementAPI)1 UsersImportOptions (com.auth0.client.mgmt.filter.UsersImportOptions)1 EmailVerificationIdentity (com.auth0.json.mgmt.EmailVerificationIdentity)1 UsersExportField (com.auth0.json.mgmt.jobs.UsersExportField)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1