title: Login with openid on wso2is from java application
body: <p>I would like to make a java application that make login and approve authorization using openId on wso2is as made playground2 (the sample released with wso2is) but i want to use apache httpclient.</p>
  
  <p>I can make the login and the step until the approve, when I make approve the response is always "<a href="https://192.168.3.40:9443/carbon/../authenticationendpoint/oauth2_error.do?oauthErrorCode=invalid_request&amp;oauthErrorMsg=Invalid+authorization+request" rel="nofollow">https://192.168.3.40:9443/carbon/../authenticationendpoint/oauth2_error.do?oauthErrorCode=invalid_request&amp;oauthErrorMsg=Invalid+authorization+request</a>"</p>
  
  <p>this is my code:</p>
  
  <pre><code>httpget = new HttpGet( "https://" + host + ":9443/oauth2/authorize?scope=openid&amp;response_type=code&amp;redirect_uri=http%3A%2F%2F192.168.0.37%3A8080%2Fplayground2%2Foauth2client&amp;client_id=IfhWIq5d9rHJXFDtyvICEga3AvUa" );
  
  referer = "http://192.168.0.37:8080/playground2/oauth2.jsp?reset=true";
  httpget.setHeader( HttpHeaders.REFERER, referer );
  httpget.setHeader( HttpHeaders.USER_AGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36" );
  
  response = httpclient.execute( httpget, context );
  entity = response.getEntity();
  content = EntityUtils.toString( entity );
  sessionDataKey = getSessionDataKey( content );
  
  List&lt;Cookie&gt; cl = cookieStore.getCookies();
  
  for (Cookie c: cl){
     if (c.getName().equalsIgnoreCase( "jsessionid") &amp;&amp; c.getPath().equals("/"))
         jsessionid = c.getValue();
  }
  
  HttpPost httpostAuth = new HttpPost( "https://" + host + ":9443/commonauth" );
  
  
  nvps.clear();
  nvps.add( new BasicNameValuePair( "username", "ltosi" ) );
  nvps.add( new BasicNameValuePair( "password", "ltosi" ) );
  nvps.add( new BasicNameValuePair( "sessionDataKey", sessionDataKey ) );
  nvps.add( new BasicNameValuePair( "Sign In", "Sign In" ) );
  
  referer = "https://192.168.3.40:9443/authenticationendpoint/login.do;jsessionid="+jsessionid+"?sessionDataKey="+sessionDataKey+"&amp;type=oidc&amp;commonAuthCallerPath=/oauth2/authorize&amp;forceAuthenticate=false&amp;checkAuthentication=false&amp;relyingParty=IfhWIq5d9rHJXFDtyvICEga3AvUa&amp;tenantId=-1234&amp;scope%3Dopenid%26response_type%3Dcode%26redirect_uri%3Dhttp%253A%252F%252F192.168.0.37%253A8080%252Fplayground2%252Foauth2client%26client_id%3DIfhWIq5d9rHJXFDtyvICEga3AvUa&amp;authenticators=BasicAuthenticator:LOCAL";
  httpostAuth.setHeader( HttpHeaders.REFERER, referer );
  httpostAuth.setHeader( HttpHeaders.USER_AGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36" );        
  httpostAuth.setEntity( new UrlEncodedFormEntity( nvps, HTTP.UTF_8 ) );
  
  response = httpclient.execute( httpostAuth, context );
  entity = response.getEntity();
  content = EntityUtils.toString( entity );
  
  httpget = new HttpGet( response.getLastHeader( "Location" ).getValue() );
          httpget.setHeader( HttpHeaders.REFERER, referer );
          httpget.setHeader( HttpHeaders.USER_AGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36" );
  
  response = httpclient.execute( httpget, context );
  entity = response.getEntity();
  content = EntityUtils.toString( entity );
  
  httpost = new HttpPost( "https://" + host + ":9443/oauth2/authorize" );
  
  referer = "https://192.168.3.40:9443/authenticationendpoint/oauth2_consent.do?loggedInUser=ltosi%40carbon.super&amp;application=playground2&amp;scope=openid&amp;sessionDataKeyConsent="+sessionDataKey+"&amp;spQueryParams=scope%3Dopenid%26response_type%3Dcode%26redirect_uri%3Dhttp%253A%252F%252F192.168.0.37%253A8080%252Fplayground2%252Foauth2client%26client_id%3DIfhWIq5d9rHJXFDtyvICEga3AvUa";
  httpost.setHeader( HttpHeaders.REFERER, referer );
  httpost.setHeader( HttpHeaders.USER_AGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.81 Safari/537.36" );
  httpost.setHeader( "Origin", "https://192.168.3.40:9443" );
  httpost.setHeader( "Host", "192.168.3.40:9443" );
  
  httpost.setEntity( new UrlEncodedFormEntity( nvps, HTTP.UTF_8 ) );
  nvps.clear();
  
  nvps.add( new BasicNameValuePair( "sessionDataKeyConsent", sessionDataKey ) );
  nvps.add( new BasicNameValuePair( "consent", "approve" ) );
  httpost.setEntity( new UrlEncodedFormEntity( nvps, HTTP.UTF_8 ) );
  
  response = httpclient.execute( httpost, context );
  entity = response.getEntity();
  </code></pre>