Hi All,
I have an issue to fetch the access token by using OKhttp query. I manage to do it with postman and powershell but when I try it in Java, I got an unknown host exception.
public String getToken() throws IOException {
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
String params = "grant_type=password&username=user_email&password=pwd&scope=openid";
RequestBody body = RequestBody.create(params, mediaType);
Request request = new Request.Builder()
.url("https://dev-***********.okta.com/oauth2/default/v1/token")
.post(body)
.addHeader("Accept", "application/json")
.addHeader("authorization", "Basic MG9hOTZ4amd6OFZxalBieXM1ZDc6WGUyejBncjVxMkhyUmQxWkttdGZqQmFzTnh4WDVNTDBLSjh3VjZDVQ")
.addHeader("Content-Type", "application/x-www-form-urlencoded")
.build();
try (Response response = client.newCall(request).execute()) {
return response.body().string();
}
}
I don t manage to see where is the mistake. If you have an idea.
Regards
Mat