how to authenticate API xml output
I got a requirement
when i hit http://localhost:4502/content/website/api/jcr:content.api.xml URL through the postman i need to authenticate it.
Any Suggestions how to authenticate.
I got a requirement
when i hit http://localhost:4502/content/website/api/jcr:content.api.xml URL through the postman i need to authenticate it.
Any Suggestions how to authenticate.
Hope Below code will help
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.json.JSONObject;
public class MyOAuthClient {
public String getAccessToken(String clientId, String clientSecret) {
String accessToken = null;
try {
// Create an HttpClient object
HttpClient httpClient = HttpClientBuilder.create().build();
// Create a HttpPost object with the authentication endpoint URL
HttpPost httpPost = new HttpPost("http://localhost:4502/oauth/token");
// Create a JSON object with the grant type, client ID, and client secret
JSONObject json = new JSONObject();
json.put("grant_type", "client_credentials");
json.put("client_id", clientId);
json.put("client_secret", clientSecret);
// Set the JSON object as the entity of the HttpPost request
StringEntity entity = new StringEntity(json.toString());
entity.setContentType("application/json");
httpPost.setEntity(entity);
// Execute the HttpPost request and get the response
HttpResponse response = httpClient.execute(httpPost);
HttpEntity responseEntity = response.getEntity();
// Parse the response JSON and get the access token
JSONObject responseJson = new JSONObject(responseEntity.getContent());
accessToken = responseJson.getString("access_token");
} catch (Exception e) {
e.printStackTrace();
}
return accessToken;
}
}
In this code, the getAccessToken method sends an OAuth 2 authentication request to the AEM instance's token endpoint using the client ID and secret provided as arguments. The response is parsed to extract the access token, which is then returned by the method.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.