Advertisement
Guest User

Untitled

a guest
Jun 6th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.25 KB | None | 0 0
  1. public static final String AUTH_URL = 'https://test.salesforce.com/services/oauth2/token';
  2. public static final String CONSUMER_KEY = '3MVG97wqanbUM37IrVAYa3ZeAtHO0PIQOmIJOQPSG3C7ZlKqV6qQ28LOLPkefh_JEfzMwrWX2JVJ.k0o6TgEr';
  3. public static final String CONSUMER_SECRET = '5259521906564034481';
  4. public static final String API_USERNAME = 'admin@unisource.com.salesiq';
  5. public static final String API_PASSWORD = 'P@ssw0rd1';
  6.  
  7.  
  8. String reqString = String.format('grant_type=password&client_id={0}&client_secret={1}&username={2}&password={3}',
  9.                                  new String[] {EncodingUtil.urlEncode(CONSUMER_KEY, 'UTF-16'),
  10.                                      EncodingUtil.urlEncode(CONSUMER_SECRET, 'UTF-16'),
  11.                                      EncodingUtil.urlEncode(API_USERNAME, 'UTF-16'),
  12.                                      EncodingUtil.urlEncode(API_PASSWORD, 'UTF-16')});
  13.  
  14.  
  15. System.debug(reqString);
  16. HttpRequest authRequest = new HttpRequest();
  17. authRequest.setMethod('POST');
  18. authRequest.setHeader('Content-Type', 'application/x-www-form-urlencoded');
  19. authRequest.setBody(reqString);
  20. authRequest.setEndpoint(AUTH_URL);
  21.  
  22. Http http = new Http();
  23. HttpResponse authResponse = http.send(authRequest);
  24. System.debug(authResponse.getBody());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement