Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AADSTS700016 while obtaining credential using Python SDK and a Service Principal Account #3742

Closed
kmai opened this issue Nov 5, 2018 · 11 comments
Labels
Graph question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@kmai
Copy link

kmai commented Nov 5, 2018

While instantiating a ServicePrincipalAccount:

from azure.graphrbac import GraphRbacManagementClient
from azure.common.credentials import ServicePrincipalCredentials

rbac_credentials = ServicePrincipalCredentials(
    client_id=azure_cfg['azure']['client_id'],
    secret=azure_cfg['azure']['secret'],
    tenant_id=azure_cfg['azure']['tenant'],
    resource="https://graph.windows.net"
)

print("RBAC Credentials created")

graphrbac_client = GraphRbacManagementClient(
    rbac_credentials,
    azure_cfg['azure']['tenant']
)

Even though I have proper permissions with the configured Application SPA (graph API access plus resource management), I get the following message:

{
    "error":"unauthorized_client",
    "error_description":"AADSTS700016: Application with identifier '844711df-d6fa-45ef-b83d-1bf9c0dcca88' was not found in the directory 'graph.windows.net'. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You may have sent your authentication request to the wrong tenant.
    Trace ID: f9ec488e-6bd1-4b5e-a315-dc6cca186800
    Correlation ID: b869d0fc-8179-4c2e-9348-6b985263a865
    Timestamp: 2018-11-05 13:17:58Z",
    "error_codes":[700016],
    "timestamp":"2018-11-05 13:17:58Z",
    "trace_id":"f9ec488e-6bd1-4b5e-a315-dc6cca186800",
    "correlation_id":"b869d0fc-8179-4c2e-9348-6b985263a865"
}

Are Application SPAs supported? Besides API Permissions on App Registrations (Azure Active Directory), is there anything else I'm missing? There aren't many examples about this.

@lmazuel
Copy link
Member

lmazuel commented Nov 5, 2018

Hi @kmai
Based on the error:

Application with identifier '844711df-d6fa-45ef-b83d-1bf9c0dcca88' was not found in the directory 'graph.windows.net'

it seems azure_cfg['azure']['tenant'] is the string 'graph.windows.net, which is incorrect. It should be the tenant where the application was created.

Could you confirm 100% there is no mistake in your dictionnary?

@lmazuel lmazuel added Graph question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Nov 5, 2018
@kmai
Copy link
Author

kmai commented Nov 6, 2018

Hi, as per the documentation here, the resource scope for the credentials should be https://graph.windows.net

azure_cfg['azure']['tenant'] contains the tenant id. If I change the resource to point towards https://graph.microsoft.com (the new Graph API) or towards something like https://mytenant.onmicrosoft.com, it doesn't work either.

@lmazuel
Copy link
Member

lmazuel commented Nov 6, 2018

Hum, your service principal might not have the necessary permissions on the tenant actually.
@yugangw-msft opinions?

@yugangw-msft
Copy link

yugangw-msft commented Nov 7, 2018

@kmai, you need to give your service principal some permissions to the AAD Graph or MS Graph, based on your app's need. Though for other e2e, but this doc has the relevant steps which can help you.
Note, Python SDK already has the API which you can potentially automate everything. For now, please follow the UI to get familiar with the concept.

@kmai
Copy link
Author

kmai commented Nov 7, 2018

@yugangw-msft actually, I do have those (and more) permissions assigned:

SPA Permissions

@yugangw-msft
Copy link

But your code uses GraphRbacManagementClient which only works for AAD Graph, not with the MS graph like your screen snapshot reveals.
Also make sure you clicked the grant permission button

@yugangw-msft yugangw-msft reopened this Nov 7, 2018
@yugangw-msft
Copy link

And reopen if you have any other questions our help is needed

@kmai
Copy link
Author

kmai commented Nov 8, 2018

@yugangw-msft the permissions are actually granted.

Is there a Python Module to query the MS Graph API? I'm really trying to avoid writing abstractions against the REST API if there's something out there that does the job.

  • If I use my Azure Profile with ~azure.common.credentials.get_azure_cli_credentials(resource='https://graph.windows.net'), I'm able to query the AAD Graph.
  • If I try to use ~azure.common.credentials.get_azure_cli_credentials.ServicePrincipalCredentials by defining client_id, tenant, secret and resource (where resource is https://graph.windows.net), it doesn't work.

I need this to query user membership to groups and to check if groups exist.

@lmazuel
Copy link
Member

lmazuel commented Nov 9, 2018

MS Graph repo might help you and have Python samples:
https://github.com/microsoftgraph?utf8=%E2%9C%93&q=&type=&language=python

@GilGald
Copy link

GilGald commented Feb 28, 2019

@yugangw-msft the permissions are actually granted.

Is there a Python Module to query the MS Graph API? I'm really trying to avoid writing abstractions against the REST API if there's something out there that does the job.

  • If I use my Azure Profile with ~azure.common.credentials.get_azure_cli_credentials(resource='https://graph.windows.net'), I'm able to query the AAD Graph.
  • If I try to use ~azure.common.credentials.get_azure_cli_credentials.ServicePrincipalCredentials by defining client_id, tenant, secret and resource (where resource is https://graph.windows.net), it doesn't work.

I need this to query user membership to groups and to check if groups exist.

I'm also in the same situation as you,were you able to use the graph with ServicePrincipalCredentials?

@lmazuel
Copy link
Member

lmazuel commented May 7, 2021

Azure AD Graph API is now deprecated. We do not support SDK fixes to this product anymore. Please refer to this issue for additional way to get support to move to Microsoft Graph API:
azure-deprecation/dashboard#60

@lmazuel lmazuel closed this as completed May 7, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Graph question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

No branches or pull requests

4 participants