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