Guest User

Untitled

a guest
Nov 13th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. String url = LoginConstants.URL_OAUTH;
  2. HttpClient client = HttpClientBuilder.create().build();
  3. HttpPost post = new HttpPost(url);
  4.  
  5. post.addHeader(HttpHeaders.AUTHORIZATION, LoginConstants.BASIC_AUTHORIZATION);
  6. post.addHeader("Content-Type", ContentType.APPLICATION_FORM_URLENCODED.getMimeType());
  7.  
  8. List<NameValuePair> body = new ArrayList<NameValuePair>();
  9. body.add(new BasicNameValuePair(LoginConstants.GRANT_TYPE, LoginConstants.GRANT_TYPE_VALUE));
  10. body.add(new BasicNameValuePair(LoginConstants.USER_NAME, user));
  11. body.add(new BasicNameValuePair(LoginConstants.PASSWORD, password));
  12. body.add(new BasicNameValuePair(LoginConstants.SCOPE, LoginConstants.SCOPE_VALUE));
  13.  
  14. UrlEncodedFormEntity entity = new UrlEncodedFormEntity(body, CharEncoding.UTF_8);
  15. post.setEntity(entity);
  16.  
  17. HttpResponse response = client.execute(post);
  18.  
  19. OkHttpClient client = new OkHttpClient();
  20.  
  21. MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
  22. RequestBody body = RequestBody.create(mediaType, "grant_type=password&username=canido&password=canido08&scope=customScope");
  23. Request request = new Request.Builder()
  24. .url("https://localhost:7001/OAuth/token")
  25. .post(body)
  26. .addHeader("authorization", "Basic XXX")
  27. .addHeader("content-type", "application/x-www-form-urlencoded")
  28. .addHeader("cache-control", "no-cache")
  29. .addHeader("postman-token", "b81569ff-5f3f-f009-d512-ef4258808e01")
  30. .build();
  31.  
  32. Response response = client.newCall(request).execute();
Add Comment
Please, Sign In to add comment