Copy link to clipboard
Copied
I have been working on automating our user management for Creative Cloud. I am able to get the JWT to send https://ims-na1.adobelogin.com/ims/exchange/jwt and receive a 200 response but I do not have the access token in the body of the response.
Is there something else I am missing?
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
KeySpec ks = new PKCS8EncodedKeySpec(privateKeyFileContent);
RSAPrivateKey privateKey = (RSAPrivateKey) keyFactory.generatePrivate(ks);
String imsHost = LocalProperties.getInstance().getProperty("imsHostBase");
String orgId = LocalProperties.getInstance().getProperty("orgId");
String technicalAccountId = LocalProperties.getInstance().getProperty("technicalAccountId");
String apiKey = LocalProperties.getInstance().getProperty("apiKey");
String metascopes = new String (LocalProperties.getInstance().getProperty("metascopes"));
String aud = "https://" + imsHost + "/c/" + apiKey;
String meta = "https://" + imsHost + "/s/" + metascopes;
jwtToken = Jwts.builder()
.setHeaderParam("Content-Type","application/x-www-form-urlencoded")
.setHeaderParam("Cache-Control","no-cache")
.setExpiration(expirationTime)
.setSubject(technicalAccountId)
.setAudience(aud)
.setIssuer(orgId)
.claim(meta, TRUE)
.signWith(RS256, privateKey).compact();
HttpsURLConnection connection;
connection = (HttpsURLConnection) new URL(imsHost).openConnection();
connection.setRequestMethod("POST"); // PUT is another valid option
connection.setRequestProperty("Cache-Control", "no-cache");
connection.setRequestProperty("Content-Type","multipart/form-data");
connection.setDoOutput(true);
connection.setDoInput(true);
connection.connect();
DataOutputStream os = new DataOutputStream(connection.getOutputStream());
os.writeBytes(urlParameters);
os.flush();
os.close();
//getResponse from POST
int responseCode = connection.getResponseCode();
System.out.println("Res msg " + connection.getResponseMessage());
System.out.println("\nSending 'POST' request to URL : " + imsHost);
System.out.println("Post parameters : " + urlParameters);
System.out.println("Response Code : " + responseCode);
if (responseCode == HttpURLConnection.HTTP_OK) {
Map<String, List<String>> mapResponse = connection.getHeaderFields();
for (Map.Entry<String,List<String>> entry : mapResponse.entrySet()) {
System.out.println("Key: " + entry.getKey() + " Value: " + entry.getValue());
}
InputStreamReader inputStream = new InputStreamReader(connection.getInputStream());
BufferedReader in = new BufferedReader(inputStream);
String inputLine;
String sbResponse = new String();
while ((inputLine = in.readLine()) != null) {
sbResponse.concat(inputLine);
}
in.close();
// print result
System.out.println(sbResponse.toString());
}
else {
BufferedReader err = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
String errorLine;
StringBuffer sbResponseError = new StringBuffer();
while ((errorLine = err.readLine()) != null) {
sbResponseError.append(errorLine);
}
err.close();
// print result
System.out.println(sbResponseError.toString());
}
Have something to add?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now