<commit_before>Azure Active Directory Graph Rbac API
=====================================

Create the client
-----------------

The following code creates an instance of the client.

See :doc:`Resource Management Authentication <quickstart_authentication>`
for details on getting a ``Credentials`` instance.

You will also need the tenant id of the AD you want to manage. Could be the AD UUID or domain name.
`You can follow this documentation to get it <https://msdn.microsoft.com/library/azure/ad/graph/howto/azure-ad-graph-api-operations-overview#TenantIdentifier>`__.

.. note:: You need to change the `resource` parameter to `https://graph.windows.net` while creating the credentials instance

.. code:: python

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

    # See above for details on creating different types of AAD credentials
    credentials = UserPassCredentials(
		'<EMAIL>',	# Your user
		'<PASSWORD>',		# Your password
		resource="https://graph.windows.net"
	)

    tenant_id = "myad.onmicrosoft.com"

    graphrbac_client = GraphRbacManagementClient(
        credentials,
        tenant_id
    )

Manage users
------------

The following code creates a user, get it directly and by list filtering, and then delete it.
`Filter syntax can be found here <https://msdn.microsoft.com/library/azure/ad/graph/howto/azure-ad-graph-api-supported-queries-filters-and-paging-options#-filter>`__.

.. code:: python

    from azure.graphrbac.models import UserCreateParameters, UserCreateParametersPasswordProfile

    user = graphrbac_client.user_operations.create(
        UserCreateParameters(
            user_principal_name="test<EMAIL>@{}".format(MY_AD_DOMAIN),
            account_enabled=False,
            display_name='<NAME>',
            mail_nickname='testbuddy',
            password_profile=UserCreateParametersPasswordProfile(
                password='<PASSWORD>',
                force_change_password_next_login=True
            )
        )
    )
    # user is a User instance
    self.assertEqual(user.display_name, '<NAME>')

    user = graphrbac_client.user.get(user.object_id)
    self.assertEqual(user.display_name, '<NAME>')

    for user in graphrbac_client.user_operations.list(filter="displayName eq '<NAME>'"):
        self.assertEqual(user.display_name, '<NAME>')

    graphrbac_client.user_operations.delete(user.object_id)
<commit_msg>Fixed indentation problem in example code<commit_after>Azure Active Directory Graph Rbac API
=====================================

Create the client
-----------------

The following code creates an instance of the client.

See :doc:`Resource Management Authentication <quickstart_authentication>`
for details on getting a ``Credentials`` instance.

You will also need the tenant id of the AD you want to manage. Could be the AD UUID or domain name.
`You can follow this documentation to get it <https://msdn.microsoft.com/library/azure/ad/graph/howto/azure-ad-graph-api-operations-overview#TenantIdentifier>`__.

.. note:: You need to change the `resource` parameter to `https://graph.windows.net` while creating the credentials instance

.. code:: python

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

    # See above for details on creating different types of AAD credentials
    credentials = UserPassCredentials(
		'<EMAIL>',	# Your user
		'<PASSWORD>',		# Your password
		resource="https://graph.windows.net"
	)

    tenant_id = "myad.onmicrosoft.com"

    graphrbac_client = GraphRbacManagementClient(
        credentials,
        tenant_id
    )

Manage users
------------

The following code creates a user, get it directly and by list filtering, and then delete it.
`Filter syntax can be found here <https://msdn.microsoft.com/library/azure/ad/graph/howto/azure-ad-graph-api-supported-queries-filters-and-paging-options#-filter>`__.

.. code:: python

    from azure.graphrbac.models import UserCreateParameters, UserCreateParametersPasswordProfile

    user = graphrbac_client.user_operations.create(
        UserCreateParameters(
            user_principal_name="<EMAIL>@{}".format(MY_AD_DOMAIN),
            account_enabled=False,
            display_name='<NAME>',
            mail_nickname='testbuddy',
            password_profile=UserCreateParametersPasswordProfile(
                password='<PASSWORD>',
                force_change_password_next_login=True
            )
        )
    )
    # user is a User instance
    self.assertEqual(user.display_name, '<NAME>')

    user = graphrbac_client.user.get(user.object_id)
    self.assertEqual(user.display_name, '<NAME>')

    for user in graphrbac_client.user_operations.list(filter="displayName eq '<NAME>'"):
        self.assertEqual(user.display_name, '<NAME>')

    graphrbac_client.user_operations.delete(user.object_id)

{'fraction_non_alphanumeric': 0.11683289232648077, 'fraction_numerical': 0.0, 'mean_word_length': 3.5542168674698793, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1499851', 'n_tokens_mistral': 1394, 'n_tokens_neox': 1347, 'n_words': 355}