[英]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.