Issue accesing APIM - listbyservice API through Java SDK
Hi Experts,
I am new to the Azure APIs and trying to access the APIs from Azure API management service through an App registred in AAD. I have followed below doc to register the app and create secrets and given the app "Resource read" permission in the APIM.
Doc for app registration: https://learn.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal#assign-a-role-to-the-application
I ma trying to use the java sdk for the API access - https://github.com/Azure/azure-sdk-for-java/blob/azure-resourcemanager-apimanagement_1.0.0-beta.3/sdk/apimanagement/azure-resourcemanager-apimanagement/README.md
below is my code snippet:
public void getApis(){
logger.info("Env: AZURE_CLIENT_ID:{} AZURE_TENANT_ID:{}, AZURE_CLIENT_SECRET:{}, AZURE_SUBSCRIPTION_ID:{}", System.getenv("AZURE_CLIENT_ID"),
System.getenv("AZURE_TENANT_ID"), System.getenv("AZURE_CLIENT_SECRET"), System.getenv("AZURE_SUBSCRIPTION_ID"));
AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE );
TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
.build();
ApiManagementManager manager = ApiManagementManager
.authenticate(credential, profile);
String resourceGroupName = "test-rg";
String serviceName = "chaitanya-test-apim-service";
PagedIterable<ApiContract> result = manager.apis().listByService(resourceGroupName, serviceName);
List<String> apiList = new ArrayList<>();
for (ApiContract api: result) {
apiList.add(api.name());
System.out.println("API Name: " + api.name());
}
}
I have set all th required Environmental variables as described in github. When I run the code I get below message for the credential object - "DefaultAzureCredential authentication failed. ---> "
Java version: 11
Attaching screenshot for the app registration config and error FYR. Could you please help here in identifuying the issue?