I am trying a post-call to generate an access token using the client username and password. I would like to know how we can achieve this through Java code.
Basically, I have username and password. I would need to get the access token to pass in below authorization header
byte[] encryptedAccessToken = null;
String username = "someUser";
String pass = "somePassword";
String auth = username + ":" + pass;
byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(StandardCharsets.ISO_8859_1));
URL obj = new URL("https://api.salesforce.com/v2/oauth/token?grant_type=openapi_2lo");
HttpURLConnection postConnection = (HttpURLConnection) obj.openConnection();
postConnection.setRequestMethod("POST");
String authorizationHeader = "Bearer " + "encodedAuth";
postConnection.setRequestProperty("Content-Type", "application/json");
postConnection.setRequestProperty("Authorization", authorizationHeader);
postConnection.setDoOutput(true);
Basically, I have a username and password. I would need to get the access token to pass in below authorizationHeader. Could you please tell me how to generate an access token using this username and password.