【问题标题】:Azure, python manage Active DirectoryAzure、python 管理 Active Directory
【发布时间】:2017-10-20 10:32:13
【问题描述】:

我是 Azure 的新手,很惊讶 Python SDK 不如 AWS 的。

我正在努力使用 python 在 Azure 中创建 Active Directory 管理网。

查看文档后,我有点困惑。我已经使用令牌进行身份验证:

from azure.common.credentials import ServicePrincipalCredentials

# Tenant ID for your Azure Subscription
TENANT_ID = 'ABCDEFGH-1234-1234-1234-ABCDEFGHIJKL'

# Your Service Principal App ID
CLIENT = 'a2ab11af-01aa-4759-8345-7803287dbd39'

# Your Service Principal Password
KEY = 'password'

credentials = ServicePrincipalCredentials(
    client_id = CLIENT,
    secret = KEY,
    tenant = TENANT_ID
)

但是对于 Active Directory,有不同的包/库,并且身份验证也不同:

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

credentials = UserPassCredentials(
            'user@domain.com',      # Your user
            'my_password',          # Your password
            resource="https://graph.windows.net"
    )

tenant_id = "myad.onmicrosoft.com"

graphrbac_client = GraphRbacManagementClient(
    credentials,
    tenant_id
)

令人困惑的是,根据Authentication Docks:

使用令牌凭据进行身份验证(旧版) 在以前版本的 SDK 中,ADAL 尚不可用,我们提供了 UserPassCredentials 类。这被认为已弃用,不应再使用。

谁能帮助我了解如何使用新的令牌凭据ServicePrincipalCredentials() 连接到 Azure 中的 Active Directory,我在 azure.graphrbac 中找不到任何引用。

我感谢任何指向示例的指针。

【问题讨论】:

    标签: azure azure-active-directory


    【解决方案1】:

    UserPassCredentials 函数正在使用 Resource Owner Password Credentials Grant ,并且此流程被视为已弃用,因为它具有多重限制,例如不支持 2FA 。

    要使用服务主体进行身份验证,建议使用ADAL 和SDK ADAL 包装器(请参阅上面链接中的Acquire Token with Client Credentials 部分)。您还可以参考文档:Authenticate with the Azure Management Libraries for Python 了解更多详细信息。

    【讨论】:

      猜你喜欢
      • 2022-01-04
      • 2014-06-16
      • 2016-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多