Get AzureAD/EntraID application properties from API call

142 views Asked by At

I am completely new with AzureAD and would like to use API calls to test that the configuration of the EntraID applications we are using are correct. Our identity team created a service principal attached to the entraID application I would like to query. I used this service principal clientId, clientSecret and our tenantId to generate a graph client (see snapshot of python code below)

        client_id = self.settings['clientId']
        tenant_id = self.settings['tenantId']
        client_secret = self.settings['clientSecret']

        client_credential = ClientSecretCredential(tenant_id, client_id, client_secret)
        graph_client = GraphServiceClient(client_credential) 

Then to get my entraID application properties, I followed the step documented here: https://learn.microsoft.com/en-us/graph/api/application-get?view=graph-rest-1.0&tabs=python#request :

result = await graph_client.applications.by_application_id('my-entraID-applicationID').get()

But it doesnt work and I get a RessourceNotFound Error:

Request_ResourceNotFound Resource 'xxxxxxxxxxxxxxxxx' does not exist or one of its queried reference-property objects are not present.

Do you know what I am doing wrong? (The app has been granted the API permission Application.Read.All, Group.Read.All, GroupMember.Read.All)

1

There are 1 answers

7
Sridevi On

I agree with @juunas, the error occurred as you are using Application ID of Entra ID app registration, instead of Object ID.

I have one Entra ID application with Application.Read.All permission of Application type granted in it:

enter image description here

Initially, I too got same error when I tried to get application properties by passing Application ID like this:

result = await graph_client.applications.by_application_id('my-entraID-applicationID').get()

Response:

enter image description here

To resolve the error, you need to pass the Object ID of Entra ID app registration that can be found here:

enter image description here

When I ran below python code by replacing Application ID with Object ID, I got the response with application properties successfully like this:

import asyncio
from azure.identity import ClientSecretCredential
from msgraph import GraphServiceClient

tenant_id = "tenantId"
client_id = "clientId"
client_secret = "clientSecret"

client_credential = ClientSecretCredential(
    tenant_id=tenant_id,
    client_id=client_id,
    client_secret=client_secret
)

graph_client = GraphServiceClient(client_credential)

async def main():
    try:
        result = await graph_client.applications.by_application_id('my-entraID-objectID').get()
        print(result)
    except Exception as e:
        print(e)

asyncio.run(main())

Response:

enter image description here

Reference: Get application - Microsoft Graph v1.0