Getting error through azure java sdk

Saurabh Pal 1 Reputation point
2022-06-27T14:25:35.797+00:00

{"error":{"code":"InvalidAuthenticationToken","message":"The received access token is not valid: at least one of the claims 'puid' or 'altsecid' or 'oid' should be present. If you are accessing as application please make sure service principal is properly created in the tenant."}}

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,013 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Saurabh Pal 1 Reputation point
    2022-06-28T06:01:00.227+00:00

    I am trying to access/modify cross account resources using the azure java sdk with the following dependencies
    "implementation 'com.azure.resourcemanager:azure-resourcemanager:2.8.0'
    implementation 'com.azure:azure-identity:1.4.6'"
    I have created an app registration in my account and associated it with a new service principal on the end user's account, created a new role and attached it to the new service principal. I am trying to modify the vm resources on the end user's account now, using the following creds
    clientId - my app registration id
    clientSecret - secret associated with my app registration
    subscriptionId - subscriptionId on the end user account
    tenantId - end user's tenant id
    I am able to read the vmInfo after logging in from the azure cli using "az login --service-principal -u clientId -p clientSecret --tenant endUserTenantId", but the same fails with above error on my azure sdk code.
    My code tries to read vmInfo with,
    "vmInfo = azureResourceManager.virtualMachines().getById(vmId);"

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.