Guest User

Untitled

a guest
Nov 3rd, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. {
  2.  
  3. client_id : 'Id_of_your_client',
  4.  
  5. username : 'your_username',
  6. password : '@#$%^&',
  7. grant_type : "password"
  8.  
  9. }
  10.  
  11. {
  12.  
  13. client_id : 'Id_of_your_client',
  14.  
  15. // client_secret : 'optional depending on the type of client',
  16.  
  17. grant_type : "refresh_token" ,
  18.  
  19. refresh_token : refresh_token_you_got_earlier
  20.  
  21. }
  22.  
  23. headers :{
  24.  
  25. Authorization : 'Bearer ' + access_token_you_got
  26.  
  27. }
  28.  
  29. String uri = "http://localhost:7080/auth/realms/{RealmName}/protocol/openid-connect/token";
  30.  
  31. HttpClient client = HttpClientBuilder.create().build();
  32. HttpPost post = new HttpPost(uri);
  33. post.setHeader("User-Agent",
  34. "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
  35. List<BasicNameValuePair> urlParameters = new ArrayList<BasicNameValuePair>();
  36. urlParameters.add(new BasicNameValuePair("grant_type", "password"));
  37. urlParameters.add(new BasicNameValuePair("client_id", {ClientName}));
  38. urlParameters.add(new BasicNameValuePair("username", {UserName}));
  39. urlParameters.add(new BasicNameValuePair("password", {Password}));
  40. post.setEntity(new UrlEncodedFormEntity(urlParameters));
  41. HttpResponse response = client.execute(post);
  42. System.out.println("Response Code : " + response.getStatusLine().getStatusCode());
  43. BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
  44. StringBuffer result = new StringBuffer();
  45. String line1 = "";
  46. while ((line1 = rd.readLine()) != null) {
  47. result.append(line1);
  48. }
  49. System.out.println(result);
Add Comment
Please, Sign In to add comment