[keycloak-user] Direct access (keycloak migration from 1.1.0 to 1.4.0)

Bill Burke bburke at redhat.com
Thu Aug 6 11:57:55 EDT 2015


GRANT_TYPE should be "password"

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

-- 
Bill Burke
JBoss, a division of Red Hat
http://bill.burkecentral.com


More information about the keycloak-user mailing list