I am trying to call the Azure API Management Rest Api with Adal 4 Java and based on following example: https://blogs.msdn.microsoft.com/azureossds/2015/06/23/authenticating-azure-resource-management-rest-api-requests-using-java/
The code works fine for the part where I take the pregenerated Access-Token from the API Management UI, but I fail when I try to do it programatically.
Working code:
String accessToken = "sometoken";
HttpGet request = new HttpGet("https://testapics.management.azure-api.net/apis/subscription/?api-version=2017-03-01");
request.addHeader("Authorization", "Bearer " + accessToken);
response = client.execute(request);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
What are the Identifier, Primary and Secondary key needed for in relation to the example. Do I still have to register the rest api as an application in Azure AD and create a service principal for it?
This is the failing part:
private AuthenticationResult getAccessTokenFromUserCredentials() throws Exception {
AuthenticationContext context = null;
AuthenticationResult result = null;
ExecutorService service = null;
try {
service = Executors.newFixedThreadPool(1);
context = new AuthenticationContext(AUTHORITY, false, service);
ClientCredential credential = new ClientCredential("integration", "passwort");
Future<AuthenticationResult> future = context.acquireToken("https://management.azure.com/", credential, null);
result = future.get();
} finally {
service.shutdown();
}
if (result == null) {
throw new ServiceUnavailableException("authentication result was null");
}
return result;
}
I always get com.microsoft.aad.adal4j.AuthenticationException: {"error_description":"AADSTS70001: Application with identifier 'integration' was not found in the directory when trying to execute with token generation.
Thanks