Advertisement
Guest User

Untitled

a guest
Mar 14th, 2019
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. @Test
  2. public void whenLoadApplication_thenSuccess() {
  3. String accessToken = obtainAccessToken("7597133091274");
  4. System.out.println("Access Token: "+accessToken);
  5. }
  6.  
  7. private String obtainAccessToken(String clientId) {
  8. String username = "fheras.garcia@gmail.com";
  9. String password = "f@r1thjhg";
  10. String token_url = "http://localhost:9001/tw-auth-server/oauth/token";
  11. String secret = "33b17e044ee6a4fa383f46ec6e28ea1d";
  12.  
  13. final Map<String, String> params = new HashMap<String, String>();
  14. params.put("grant_type", "password");
  15. params.put("client_id", clientId);
  16. params.put("username", username);
  17. params.put("password", password);
  18.  
  19. final Response response = RestAssured.given().auth()
  20. .preemptive()
  21. .basic(clientId, secret)
  22. .and().with().params(params)
  23. .when().post(token_url);
  24.  
  25. return response.jsonPath().getString("access_token");
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement