获取Azure服务主体的object_id。

huangapple go评论92阅读模式
英文:

retrieve the object_id of the Azure service principal

问题

如何使用Python API程序化地检索Azure服务主体的object_id?

获取Azure服务主体的object_id。

英文:

How can I retrieve the object_id of an Azure service principal programatically using the Python APIs?

获取Azure服务主体的object_id。

答案1

得分: 2

我尝试在我的环境中执行相同操作并获得以下结果:

检索Azure AD应用程序的ObjectID,请尝试以下代码:

获取Azure服务主体的object_id。

  1. from azure.identity import ClientSecretCredential
  2. from azure.graphrbac import GraphRbacManagementClient
  3. from msgraph.core import GraphClient
  4. def get_object_id():
  5. app_id = "AppID"
  6. tenant_id = "TenantID"
  7. client_id = "ClientID"
  8. client_secret = "ClientSecret"
  9. credential = ClientSecretCredential(tenant_id, client_id, client_secret)
  10. client = GraphClient(credential=credential)
  11. endpoint = "/applications"
  12. select = "displayName,id,appId"
  13. req_filter = f"appId eq '{app_id}'"
  14. request_url = f'{endpoint}?$select={select}&$filter={req_filter}'
  15. response = client.get(request_url)
  16. print(response.json()['value'][0]['id'])
  17. get_object_id()

获取Azure服务主体的object_id。

要获取Azure服务主体(企业应用程序)的ObjectID,请尝试以下代码:

  1. from azure.identity import ClientSecretCredential
  2. from azure.graphrbac import GraphRbacManagementClient
  3. from msgraph.core import GraphClient
  4. def get_object_id():
  5. app_id = "AppID"
  6. tenant_id = "TenantID"
  7. client_id = "ClientID"
  8. client_secret = "ClientSecret"
  9. credential = ClientSecretCredential(tenant_id, client_id, client_secret)
  10. client = GraphClient(credential=credential)
  11. endpoint = "/servicePrincipals"
  12. select = "displayName,id,appId"
  13. req_filter = f"appId eq '{app_id}'"
  14. request_url = f'{endpoint}?$select={select}&$filter={req_filter}'
  15. response = client.get(request_url)
  16. print(response.json()['value'][0]['id'])
  17. get_object_id()

获取Azure服务主体的object_id。

英文:

I attempted to do the same in my environment and got the following results:

To retrieve the ObjectID of the Azure AD Application try the below code:

获取Azure服务主体的object_id。

  1. from azure.identity import ClientSecretCredential
  2. from azure.graphrbac import GraphRbacManagementClient
  3. from msgraph.core import GraphClient
  4. def get_object_id():
  5. app_id = "AppID"
  6. tenant_id = "TenantID"
  7. client_id = "ClientID"
  8. client_secret = "ClientSecret"
  9. credential = ClientSecretCredential(tenant_id, client_id, client_secret)
  10. client = GraphClient(credential=credential)
  11. endpoint = "/applications"
  12. select = "displayName,id,appId"
  13. req_filter = f"appId eq '{app_id}'"
  14. request_url = f'{endpoint}?$select={select}&$filter={req_filter}'
  15. response = client.get(request_url)
  16. print(response.json()['value'][0]['id'])
  17. get_object_id()

获取Azure服务主体的object_id。

To get the ObjectID of the Azure Service Principal (Enterprise Application) try the below code:

  1. from azure.identity import ClientSecretCredential
  2. from azure.graphrbac import GraphRbacManagementClient
  3. from msgraph.core import GraphClient
  4. def get_object_id():
  5. app_id = "AppID"
  6. tenant_id = "TenantID"
  7. client_id = "ClientID"
  8. client_secret = "ClientSecret"
  9. credential = ClientSecretCredential(tenant_id, client_id, client_secret)
  10. client = GraphClient(credential=credential)
  11. endpoint = "/servicePrincipals"
  12. select = "displayName,id,appId"
  13. req_filter = f"appId eq '{app_id}'"
  14. request_url = f'{endpoint}?$select={select}&$filter={req_filter}'
  15. response = client.get(request_url)
  16. print(response.json()['value'][0]['id'])
  17. get_object_id()

获取Azure服务主体的object_id。

huangapple
  • 本文由 发表于 2023年4月17日 20:35:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76035215.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定