Modifier

Partager via


Bibliothèques Azure Active Directory Graph pour PythonAzure Active Directory Graph libraries for Python

Important

Depuis février 2019, nous avons lancé le processus ayant pour but de déprécier certaines versions antérieures de l’API Azure Active Directory Graph au profit de l’API Microsoft Graph.As of February 2019, we started the process to deprecate some earlier versions of Azure Active Directory Graph API in favor of the Microsoft Graph API.

Pour plus de détails, de mises à jour et de délais, consultez la page Microsoft Graph ou Azure AD Graph dans le centre de développement Office.For details, updates, and time frames, see Microsoft Graph or the Azure AD Graph in the Office Dev Center.

Pour l’avenir, les applications doivent utiliser l’API Microsoft Graph.Moving forward, applications should use the Microsoft Graph API.

Vue d'ensembleOverview

Authentifiez des utilisateurs et contrôlez l’accès aux applications et aux API avec Active Directory Graph.Sign-on users and control access to applications and APIs with Active Directory Graph.

Bibliothèque clienteClient library

pip install azure-graphrbac 

ExemplesExample

Notes

Vous devez remplacer le paramètre de ressource par https://graph.windows.net lors de la création de l’instance d’informations d’identificationYou need to change the resource parameter to https://graph.windows.net while creating the credentials instance

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   
)   

Le code suivant crée un utilisateur. Récupérez-le en filtrant la liste et supprimez-le.The following code creates a user, get it directly and by list filtering, and then delete it.

from azure.graphrbac.models import UserCreateParameters, PasswordProfile    
 user = graphrbac_client.users.create(  
    UserCreateParameters(   
        user_principal_name="testbuddy@{}".format(MY_AD_DOMAIN),    
        account_enabled=False,  
        display_name='Test Buddy',  
        mail_nickname='testbuddy',  
        password_profile=PasswordProfile(   
            password='MyStr0ngP4ssword',    
            force_change_password_next_login=True   
        )   
    )   
)   
# user is a User instance   
self.assertEqual(user.display_name, 'Test Buddy')   
 user = graphrbac_client.users.get(user.object_id)  
self.assertEqual(user.display_name, 'Test Buddy')   
 for user in graphrbac_client.users.list(filter="displayName eq 'Test Buddy'"): 
    self.assertEqual(user.display_name, 'Test Buddy')   
 graphrbac_client.users.delete(user.object_id)