Reputation: 2111
I'm very new to Azure and was surprised that the python SDK was not as good as AWS' one.
I'm struggeling to get create managenet of Active Directory in Azure with python.
After looking at the documentation I'm a bit confused. I have got the authentication with token working:
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
)
However for the Active Directory there is different pockage/library and the authentication is different:
from azure.graphrbac import GraphRbacManagementClient
from azure.common.credentials import UserPassCredentials
credentials = UserPassCredentials(
'[email protected]', # Your user
'my_password', # Your password
resource="https://graph.windows.net"
)
tenant_id = "myad.onmicrosoft.com"
graphrbac_client = GraphRbacManagementClient(
credentials,
tenant_id
)
The confusing bit is that accodring to Authentication Docks:
Authenticate with token credentials (legacy) In previous version of the SDK, ADAL was not yet available and we provided a UserPassCredentials class. This is considered deprecated and should not be used anymore.
Can anyone help me to understand how can I connect to Active Directory in Azure with python using the new tocken credentials ServicePrincipalCredentials(), I can't find any references to it in azure.graphrbac.
I appriciate any pointers to examples.
Upvotes: 1
Views: 876
Reputation: 27538
The UserPassCredentials function is using Resource Owner Password Credentials Grant , and this flow is considered deprecated because it has multi restriction such as don't support 2FA .
To use a Service Principal for authentication , it is recommended to use ADAL and the SDK ADAL wrapper(refer to Acquire Token with Client Credentials
section in above link) . You would also refer to document :Authenticate with the Azure Management Libraries for Python for more details.
Upvotes: 0