Hi,
this is a very basic question, but I am not getting through in posting a successful oauth call for a Jmix app.
The code I am using is as follows:
public class SimpleCall {
public static void main(String[] args) throws Exception{
String url = "http://localhost:8080/oauth/token";
DefaultHttpClient http = new DefaultHttpClient();
CredentialsProvider cp = new BasicCredentialsProvider();
cp.setCredentials(new AuthScope("localhost", 8080),
new UsernamePasswordCredentials("client", "secret"));
http.setCredentialsProvider(cp);
HttpPost postRequest = new HttpPost(url);
postRequest.addHeader("Content-Type","application/x-www-form-urlencoded");
//postRequest.addHeader("Authorization", "client secret");
postRequest.getParams().setParameter("grant_type", "password").setParameter("username", "admin").setParameter("password", "admin");
HttpResponse response = http.execute(postRequest);
if (response.getStatusLine().getStatusCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ response.getStatusLine().getStatusCode());
}
BufferedReader br = new BufferedReader(
new InputStreamReader((response.getEntity().getContent())));
String output;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
}
http.getConnectionManager().shutdown();
}
Does “client/secret” need to be something different? In CUBA you used to have the parameter “Basic Y2xpZW50OnNlY3JldA==”, so here client/secret looks pretty “open”, however via cURL following the instructions in Getting Started with REST :: Jmix Documentation I managed to retrieve auth_token’s.
No idea why I keep getting 400/401 http errors when launching these calls. I would appreciate if someone could post a successfull call to a Jmix app or share any insights on how to put this in the right path.
Many thanks in advance.
Regards,
Carlos.