Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- client_id : 'Id_of_your_client',
- username : 'your_username',
- password : '@#$%^&',
- grant_type : "password"
- }
- {
- client_id : 'Id_of_your_client',
- // client_secret : 'optional depending on the type of client',
- grant_type : "refresh_token" ,
- refresh_token : refresh_token_you_got_earlier
- }
- headers :{
- Authorization : 'Bearer ' + access_token_you_got
- }
- String uri = "http://localhost:7080/auth/realms/{RealmName}/protocol/openid-connect/token";
- HttpClient client = HttpClientBuilder.create().build();
- HttpPost post = new HttpPost(uri);
- post.setHeader("User-Agent",
- "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
- List<BasicNameValuePair> urlParameters = new ArrayList<BasicNameValuePair>();
- urlParameters.add(new BasicNameValuePair("grant_type", "password"));
- urlParameters.add(new BasicNameValuePair("client_id", {ClientName}));
- urlParameters.add(new BasicNameValuePair("username", {UserName}));
- urlParameters.add(new BasicNameValuePair("password", {Password}));
- post.setEntity(new UrlEncodedFormEntity(urlParameters));
- HttpResponse response = client.execute(post);
- System.out.println("Response Code : " + response.getStatusLine().getStatusCode());
- BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
- StringBuffer result = new StringBuffer();
- String line1 = "";
- while ((line1 = rd.readLine()) != null) {
- result.append(line1);
- }
- System.out.println(result);
Add Comment
Please, Sign In to add comment