skip to Main Content

I have an application which is registered in Azure (followed this guide). I have the application-id for this application, and I would like to find its object-id by using Azure API (I am using python library). How can I retrieve the object-id?

2

Answers


  1. Chosen as BEST ANSWER

    I found that msgraph-core (in preview) can be used for this purpose.

    Sample code:

    def get_object_id(self, app_id, tenant_id, client_id, client_secret):
        credential = ClientSecretCredential(tenant_id, client_id, client_secret)        
        client = GraphClient(credential=credential)
        endpoint = "/servicePrincipals"
        select = "displayName,id,appId"
        req_filter = f"appId eq '{app_id}'"
        request_url = f'{endpoint}?$select={select}&$filter={req_filter}'
    
        response = client.get(request_url)
        return response.json()['value'][0]['id']
    

  2. If you need the object id for the service principal, you can use the service principal list endpoint with a filter. https://learn.microsoft.com/en-us/graph/api/serviceprincipal-list?view=graph-rest-1.0&tabs=http

    Example filter: $filter=appId eq 'your-app-id'

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search