简体   繁体   English

如何使用 python SDK 访问 azure AD

[英]How to access azure AD using python SDK

I am new to Azure, I want to write a python function to access Azure AD and list the existing groups there, I am facing issues logging into azure.我是 Azure 的新手,我想编写一个 python 函数来访问 Azure AD 并列出那里的现有组,我在登录 azure 时遇到问题。 I have been working in AWS there I use boto3 as SDK and I use the command line or programmatic acess.我一直在 AWS 工作,我使用 boto3 作为 SDK,并使用命令行或编程访问。 Following is the code that I have以下是我拥有的代码

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

# See above for details on creating different types of AAD credentials
credentials = UserPassCredentials(
            'user@domain.com',      # The user id I use to login into my personal account
            'my_password',          # password of that account 
            resource="https://graph.windows.net"
    )

tenant_id = "82019-1-some-numbers"

graphrbac_client = GraphRbacManagementClient(
    credentials,
    tenant_id
)

I want to know which is professional way of logging into azure, how do i list the groups present in my azure AD, what code changes do i have to do for that我想知道哪种是登录 azure 的专业方式,如何列出我的 azure AD 中存在的组,为此我需要做哪些代码更改

To retrieve list of Azure AD groups, make sure to grant Directory.Read.All for your application like below:要检索 Azure AD 组的列表,请确保为您的应用程序授予Directory.Read.All ,如下所示:

Go to Azure Portal -> Azure Active Directory -> App Registrations -> Your App -> API permissions转到 Azure 门户 -> Azure Active Directory -> 应用注册 -> 您的应用 -> API 权限

在此处输入图像描述

You can make use of below script to get the list of Azure AD Groups by Krassy in this SO Thread :您可以使用以下脚本在此SO Thread中通过Krassy获取 Azure AD 组列表:

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

credentials = ServicePrincipalCredentials(
    client_id="Client_ID",
    secret="Secret",
    resource="https://graph.microsoft.com",
    tenant = 'tenant.onmicrosoft.com'
)
tenant_id = 'tenant_id'
graphrbac_client = GraphRbacManagementClient(credentials,tenant_id)
groups = graphrbac_client.groups.list()
for g in groups:
     print(g.display_name)

For more in detail, please refer below links:更多详细信息,请参考以下链接:

Azure Python SDK - Interact with Azure AD by Joy Wang Azure Python SDK - Joy Wang 与 Azure AD 交互

How to access the list of Azure AD Groups using python by Will Shao - MSFT 如何使用 Python 访问 Azure AD 组列表 Will Shao - MSFT

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Azure 函数中使用 cosmosdb python SDK - Using cosmosdb python SDK in Azure functions 使用 python azure sdk 查找 blob 大小 - using python azure sdk find blob size 在 Azure 的 Python 服务总线 SDK 中,如何查询命名空间的共享访问策略? - In Azure's Python service bus SDK, how do I query the shared access policies of a namespace? 我们如何在后端验证来自 azure AD 的访问令牌? - How do we validate the access token from azure AD in backend? 如何正确导入适用于 Python 3.6 的 Azure SDK - How to correctly import Azure SDK for Python 3.6 如何过滤 Azure SDK 中的 blob 为 Python - How to filter blobs in Azure SDK for Python 无法使用 Python SDK 访问 Smartsheet - Unable to access Smartsheet using Python SDK 如何使用azure-sdk-for-python在Azure队列中禁用Nagle算法 - How to disable Nagle algorithm in Azure queue with azure-sdk-for-python python SDK 上的 Azure Webjobs - Azure Webjobs on a python SDK 如何使用 Python SDK 为我在 Azure 数据湖中创建的文件设置到期日期? - How do I set an expiration date on a file I create in the Azure Data lake using the Python SDK?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM