<div dir="ltr"><div><div class="gmail_signature">Hi all<br><br></div><div class="gmail_signature">I have a problem with direct access. I try to use similar code like is on page:<br><a href="http://keycloak.github.io/docs/userguide/html/direct-access-grants.html">http://keycloak.github.io/docs/userguide/html/direct-access-grants.html</a><br></div><div class="gmail_signature">but every time I'm reciving bad request: status 400.<br><br></div><div class="gmail_signature">There is one change comparing version 1.4.0.Final with version 1.1.0.Final:<br>formparams.add(new BasicNameValuePair(OAuth2Constants.GRANT_TYPE, passwordValue));<br></div><div class="gmail_signature">I added into passwordValue password for user which was created in auth app before (not "secret").<br></div><div class="gmail_signature"><br></div><div class="gmail_signature">My code looks like this:<br></div><div class="gmail_signature"><br>HttpPost post = new HttpPost(KeycloakUriBuilder.fromUri("<a href="http://IPIPIPIP:8080/auth">http://IPIPIPIP:8080/auth</a>").path(ServiceUrlConstants.TOKEN_PATH).build(realmName));<br> List <NameValuePair> formparams = new ArrayList <NameValuePair>();<br> formparams.add(new BasicNameValuePair(OAuth2Constants.GRANT_TYPE, passwordValue));<br> formparams.add(new BasicNameValuePair("username", "userName"));<br> formparams.add(new BasicNameValuePair("password", passwordValue));<br><br> try {<br> /*String authorization = BasicAuthHelper.createHeader("appNameId", secretAppName);//secretAppName<br> post.setHeader("Authorization", authorization);*/<br> formparams.add(new BasicNameValuePair(OAuth2Constants.CLIENT_ID, "appNameId"));<br> UrlEncodedFormEntity form = new UrlEncodedFormEntity(formparams, "UTF-8");<br> post.setEntity(form);<br> <br> final HttpClient client = new HttpClientBuilder().disableTrustManager().build();<br> HttpResponse response = client.execute(post);<br> int status = response.getStatusLine().getStatusCode();<br> HttpEntity entity = response.getEntity();<br> if (status != 200) {<br> throw new IOException("Bad status: " + status);<br> }<br><br></div><div class="gmail_signature">Any ideas how to solve it ?<br></div><div class="gmail_signature"><br></div><div class="gmail_signature"><i>thanks<br><br></i></div><div class="gmail_signature"><i>regards<br></i></div><div class="gmail_signature"><div><i>--</i></div><i>Emil Posmyk<br></i></div></div>
</div>