Search in sources :

Example 11 with Connection

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

the class MultipartRequestTest method shouldParseJSONErrorResponseWithErrorDescription.

@Test
public void shouldParseJSONErrorResponseWithErrorDescription() throws Exception {
    MultipartRequest<List> request = new MultipartRequest<>(client, server.getBaseUrl(), "POST", listType);
    request.addPart("non_empty", "body");
    server.jsonResponse(AUTH_ERROR_WITH_ERROR_DESCRIPTION, 400);
    Exception exception = null;
    try {
        request.execute();
        server.takeRequest();
    } catch (Exception e) {
        exception = e;
    }
    assertThat(exception, is(notNullValue()));
    assertThat(exception, is(instanceOf(APIException.class)));
    assertThat(exception.getCause(), is(nullValue()));
    assertThat(exception.getMessage(), is("Request failed with status code 400: the connection was not found"));
    APIException authException = (APIException) exception;
    assertThat(authException.getDescription(), is("the connection was not found"));
    assertThat(authException.getError(), is("invalid_request"));
    assertThat(authException.getStatusCode(), is(400));
}
Also used : APIException(com.auth0.exception.APIException) List(java.util.List) RecordedMultipartRequest(com.auth0.net.multipart.RecordedMultipartRequest) APIException(com.auth0.exception.APIException) RateLimitException(com.auth0.exception.RateLimitException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ExpectedException(org.junit.rules.ExpectedException) Auth0Exception(com.auth0.exception.Auth0Exception) IOException(java.io.IOException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Example 12 with Connection

use of com.auth0.json.mgmt.Connection in project chefly_android by chef-ly.

the class MainActivity method socialLogin.

private void socialLogin(String connection) {
    // getString(R.string.auth0_domain
    Auth0 auth0 = new Auth0(getString(R.string.auth0_client_id), getString(R.string.auth0_domain));
    WebAuthProvider.init(auth0).withConnection(connection).start(MainActivity.this, new AuthCallback() {

        @Override
        public void onFailure(@NonNull Dialog dialog) {
            dialog.show();
        }

        @Override
        public void onFailure(final AuthenticationException exception) {
            // Show error to the user
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    Log.d(TAG, "LOGIN FAIL");
                    String errorMsg = "Sign in request failed";
                    showToast(errorMsg);
                }
            });
        }

        @Override
        public void onSuccess(@NonNull Credentials credentials) {
            // Navigate to your next activity
            startRecipeListActivity("aaa");
        }
    });
}
Also used : Auth0(com.auth0.android.Auth0) AuthenticationException(com.auth0.android.authentication.AuthenticationException) AuthCallback(com.auth0.android.provider.AuthCallback) Dialog(android.app.Dialog) Credentials(com.auth0.android.result.Credentials)

Example 13 with Connection

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

the class ConnectionsEntity method delete.

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

Example 14 with Connection

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

the class MultipartRequestTest method shouldParseJSONErrorResponseWithError.

@Test
public void shouldParseJSONErrorResponseWithError() throws Exception {
    MultipartRequest<List> request = new MultipartRequest<>(client, server.getBaseUrl(), "POST", listType);
    request.addPart("non_empty", "body");
    server.jsonResponse(AUTH_ERROR_WITH_ERROR, 400);
    Exception exception = null;
    try {
        request.execute();
        server.takeRequest();
    } catch (Exception e) {
        exception = e;
    }
    assertThat(exception, is(notNullValue()));
    assertThat(exception, is(instanceOf(APIException.class)));
    assertThat(exception.getCause(), is(nullValue()));
    assertThat(exception.getMessage(), is("Request failed with status code 400: missing username for Username-Password-Authentication connection with requires_username enabled"));
    APIException authException = (APIException) exception;
    assertThat(authException.getDescription(), is("missing username for Username-Password-Authentication connection with requires_username enabled"));
    assertThat(authException.getError(), is("missing username for Username-Password-Authentication connection with requires_username enabled"));
    assertThat(authException.getStatusCode(), is(400));
}
Also used : APIException(com.auth0.exception.APIException) List(java.util.List) RecordedMultipartRequest(com.auth0.net.multipart.RecordedMultipartRequest) APIException(com.auth0.exception.APIException) RateLimitException(com.auth0.exception.RateLimitException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ExpectedException(org.junit.rules.ExpectedException) Auth0Exception(com.auth0.exception.Auth0Exception) IOException(java.io.IOException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Example 15 with Connection

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

the class CustomRequestTest method shouldParseJSONErrorResponseWithError.

@Test
public void shouldParseJSONErrorResponseWithError() throws Exception {
    CustomRequest<List> request = new CustomRequest<>(client, server.getBaseUrl(), "GET", listType);
    server.jsonResponse(AUTH_ERROR_WITH_ERROR, 400);
    Exception exception = null;
    try {
        request.execute();
        server.takeRequest();
    } catch (Exception e) {
        exception = e;
    }
    assertThat(exception, is(notNullValue()));
    assertThat(exception, is(instanceOf(APIException.class)));
    assertThat(exception.getCause(), is(nullValue()));
    assertThat(exception.getMessage(), is("Request failed with status code 400: missing username for Username-Password-Authentication connection with requires_username enabled"));
    APIException authException = (APIException) exception;
    assertThat(authException.getDescription(), is("missing username for Username-Password-Authentication connection with requires_username enabled"));
    assertThat(authException.getError(), is("missing username for Username-Password-Authentication connection with requires_username enabled"));
    assertThat(authException.getStatusCode(), is(400));
}
Also used : APIException(com.auth0.exception.APIException) List(java.util.List) Auth0Exception(com.auth0.exception.Auth0Exception) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) APIException(com.auth0.exception.APIException) RateLimitException(com.auth0.exception.RateLimitException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ExpectedException(org.junit.rules.ExpectedException)

Aggregations

Test (org.junit.Test)16 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)13 Connection (com.auth0.json.mgmt.Connection)10 List (java.util.List)9 IOException (java.io.IOException)6 ConnectionFilter (com.auth0.client.mgmt.filter.ConnectionFilter)5 Auth0Exception (com.auth0.exception.Auth0Exception)5 APIException (com.auth0.exception.APIException)4 RateLimitException (com.auth0.exception.RateLimitException)4 RecordedMultipartRequest (com.auth0.net.multipart.RecordedMultipartRequest)4 JsonParseException (com.fasterxml.jackson.core.JsonParseException)4 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)4 ExpectedException (org.junit.rules.ExpectedException)4 VoidRequest (com.auth0.net.VoidRequest)3 File (java.io.File)3 UsersImportOptions (com.auth0.client.mgmt.filter.UsersImportOptions)2 Job (com.auth0.json.mgmt.jobs.Job)2 User (com.auth0.json.mgmt.users.User)2 FilePart (com.auth0.net.multipart.FilePart)2 KeyValuePart (com.auth0.net.multipart.KeyValuePart)2