Hi there,
I am trying to use the management API with the java client library for java ( GitHub - auth0/auth0-java: Java client library for the Auth0 platform ), but when I call a method of ManagementAPI object I get an APIException with a invalid token description and an Unauthorized error.
To get my access token i followed this tutorial: Get Management API Access Tokens for Production .
try {
HttpResponse<String> response = Unirest.post("https://kevinkons.auth0.com/oauth/token")
.header("content-type", "application/json")
.body("{\"grant_type\":\"client_credentials\"," +
"\"client_id\": \"CEFmUinQ6ZanhgTyMMdTeCr5e46PZK87\"," +
"\"client_secret\": \"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"," +
"\"audience\": \"https://kevinkons.auth0.com/api/v2/\"}")
.asString();
String accessTokenWithQuotationMarks = response.getBody().split(",")[0].split(":")[1];
String accessToken = accessTokenWithQuotationMarks.substring(1, accessTokenWithQuotationMarks.length() -1);
ManagementAPI mgmt = new ManagementAPI("https://kevinkons.auth0.com", accessToken);
UserFilter filter = new UserFilter()
.withPage(1, 20);
Request<UsersPage> request = mgmt.users().list(filter);
try {
UsersPage responsee = request.execute();
for(User u : responsee.getItems()) {
u.getEmail();
}
} catch (APIException exception) {
System.err.println("API " + exception.getDescription());
} catch (Auth0Exception exception) {
System.err.println("AUTH0" + exception.getMessage());
}
} catch (UnirestException e) {
e.printStackTrace();
}