Getting Authorization_RequestDenied Exception with Azure Java SDK

101 views Asked by At

I have written a small snippet to fetch all the service principals using Azure Java SDK. Getting this exception. What privileges do i need to give for this sdk call?

"code":"Authorization_RequestDenied","message":{"lang":"en","value":"Insufficient privileges to complete the operation."}

ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(
        "<CLIENT_ID>", "<TENANT_ID>",
        "<CLIENT_SECRET>", AzureEnvironment.AZURE);
Authenticated authenticated = Azure.configure().withLogLevel(LogLevel.NONE)
        .authenticate(credentials);
PagedList<ServicePrincipal> servicePrincipals = authenticated.servicePrincipals().list();
servicePrincipals.stream().forEach(principal -> System.out.println(principal.id()));
1

There are 1 answers

0
Santosh b On BEST ANSWER

I found what the problem is.

Whenever you try to fetch Service Principal using id it internally fetches all service principals and returns the specific service principal with that id.

I tried to fetch using getByName and it worked fine.

authenticated.servicePrincipals().getByName("<MYAPP_NAME/MYAPP_ID>");