account_setup.py
def create_aad_user(credentials, tenant_id, **kwargs):
    """
        Create an AAD application and service principal
        :param credentials: msrestazure.azure_active_directory.AdalAuthentication
        :param tenant_id: str
        :param **application_name: str
    """
    graph_rbac_client = GraphRbacManagementClient(
        credentials, tenant_id, base_url=AZURE_PUBLIC_CLOUD.endpoints.active_directory_graph_resource_id)
    application_credential = uuid.uuid4()
    try:
        display_name = kwargs.get("application_name", DefaultSettings.application_name)
        application = graph_rbac_client.applications.create(
            parameters=ApplicationCreateParameters(
                available_to_other_tenants=False,
                identifier_uris=["http://{}.com".format(display_name)],
                display_name=display_name,
                password_credentials=[
                    PasswordCredential(
                        start_date=datetime(2000, 1, 1, 0, 0, 0, 0, tzinfo=timezone.utc),
                        end_date=datetime(2299, 12, 31, 0, 0, 0, 0, tzinfo=timezone.utc),
                        value=application_credential,
                        key_id=uuid.uuid4())
                ]))
        service_principal = graph_rbac_client.service_principals.create(
            ServicePrincipalCreateParameters(app_id=application.app_id, account_enabled=True))
    except GraphErrorException as e:
        if e.inner_exception.code == "Request_BadRequest":
            application = next(
                graph_rbac_client.applications.list(
                    filter="identifierUris/any(c:c eq 'http://{}.com')".format(display_name)))

            confirmation_prompt = "Previously created application with name {} found. "\
                                  "Would you like to use it? (y/n): ".format(application.display_name)
            prompt_for_confirmation(confirmation_prompt, e, ValueError("Response not recognized. Please try again."))
            password_credentials = list(
                graph_rbac_client.applications.list_password_credentials(application_object_id=application.object_id))
            password_credentials.append(
                PasswordCredential(
                    start_date=datetime(2000, 1, 1, 0, 0, 0, 0, tzinfo=timezone.utc),
                    end_date=datetime(2299, 12, 31, 0, 0, 0, 0, tzinfo=timezone.utc),
                    value=application_credential,
                    key_id=uuid.uuid4()))
            graph_rbac_client.applications.patch(
                application_object_id=application.object_id,
                parameters=ApplicationUpdateParameters(password_credentials=password_credentials))
            service_principal = next(
                graph_rbac_client.service_principals.list(filter="appId eq '{}'".format(application.app_id)))
        else:
            raise e

    return application.app_id, service_principal.object_id, str(application_credential)

        Create an AAD application and service principal
        :param credentials: msrestazure.azure_active_directory.AdalAuthentication
        :param tenant_id: str
        :param **application_name: str
    
Create an AAD application and service principal
Create an AAD application and service principal
def create_aad_user(credentials, tenant_id, **kwargs):
    graph_rbac_client = GraphRbacManagementClient(
        credentials, tenant_id, base_url=AZURE_PUBLIC_CLOUD.endpoints.active_directory_graph_resource_id)
    application_credential = uuid.uuid4()
    try:
        display_name = kwargs.get("application_name", DefaultSettings.application_name)
        application = graph_rbac_client.applications.create(
            parameters=ApplicationCreateParameters(
                available_to_other_tenants=False,
                identifier_uris=["http://{}.com".format(display_name)],
                display_name=display_name,
                password_credentials=[
                    PasswordCredential(
                        start_date=datetime(2000, 1, 1, 0, 0, 0, 0, tzinfo=timezone.utc),
                        end_date=datetime(2299, 12, 31, 0, 0, 0, 0, tzinfo=timezone.utc),
                        value=application_credential,
                        key_id=uuid.uuid4())
                ]))
        service_principal = graph_rbac_client.service_principals.create(
            ServicePrincipalCreateParameters(app_id=application.app_id, account_enabled=True))
    except GraphErrorException as e:
        if e.inner_exception.code == "Request_BadRequest":
            application = next(
                graph_rbac_client.applications.list(
                    filter="identifierUris/any(c:c eq 'http://{}.com')".format(display_name)))
            confirmation_prompt = "Previously created application with name {} found. "\
                                  "Would you like to use it? (y/n): ".format(application.display_name)
            prompt_for_confirmation(confirmation_prompt, e, ValueError("Response not recognized. Please try again."))
            password_credentials = list(
                graph_rbac_client.applications.list_password_credentials(application_object_id=application.object_id))
            password_credentials.append(
                PasswordCredential(
                    start_date=datetime(2000, 1, 1, 0, 0, 0, 0, tzinfo=timezone.utc),
                    end_date=datetime(2299, 12, 31, 0, 0, 0, 0, tzinfo=timezone.utc),
                    value=application_credential,
                    key_id=uuid.uuid4()))
            graph_rbac_client.applications.patch(
                application_object_id=application.object_id,
                parameters=ApplicationUpdateParameters(password_credentials=password_credentials))
            service_principal = next(
                graph_rbac_client.service_principals.list(filter="appId eq '{}'".format(application.app_id)))
        else:
            raise e
    return application.app_id, service_principal.object_id, str(application_credential)
def create_aad_user ( credentials , tenant_id , ** kwargs ) : graph_rbac_client = GraphRbacManagementClient ( credentials , tenant_id , base_url = AZURE_PUBLIC_CLOUD . endpoints . active_directory_graph_resource_id ) application_credential = uuid . uuid4 ( ) try : display_name = kwargs . get ( "application_name" , DefaultSettings . application_name ) application = graph_rbac_client . applications . create ( parameters = ApplicationCreateParameters ( available_to_other_tenants = False , identifier_uris = [ "http://{}.com" . format ( display_name ) ] , display_name = display_name , password_credentials = [ PasswordCredential ( start_date = datetime ( 2000 , 1 , 1 , 0 , 0 , 0 , 0 , tzinfo = timezone . utc ) , end_date = datetime ( 2299 , 12 , 31 , 0 , 0 , 0 , 0 , tzinfo = timezone . utc ) , value = application_credential , key_id = uuid . uuid4 ( ) ) ] ) ) service_principal = graph_rbac_client . service_principals . create ( ServicePrincipalCreateParameters ( app_id = application . app_id , account_enabled = True ) ) except GraphErrorException as e : if e . inner_exception . code == "Request_BadRequest" : application = next ( graph_rbac_client . applications . list ( filter = "identifierUris/any(c:c eq 'http://{}.com')" . format ( display_name ) ) ) confirmation_prompt = "Previously created application with name {} found. " "Would you like to use it? (y/n): " . format ( application . display_name ) prompt_for_confirmation ( confirmation_prompt , e , ValueError ( "Response not recognized. Please try again." ) ) password_credentials = list ( graph_rbac_client . applications . list_password_credentials ( application_object_id = application . object_id ) ) password_credentials . append ( PasswordCredential ( start_date = datetime ( 2000 , 1 , 1 , 0 , 0 , 0 , 0 , tzinfo = timezone . utc ) , end_date = datetime ( 2299 , 12 , 31 , 0 , 0 , 0 , 0 , tzinfo = timezone . utc ) , value = application_credential , key_id = uuid . uuid4 ( ) ) ) graph_rbac_client . applications . patch ( application_object_id = application . object_id , parameters = ApplicationUpdateParameters ( password_credentials = password_credentials ) ) service_principal = next ( graph_rbac_client . service_principals . list ( filter = "appId eq '{}'" . format ( application . app_id ) ) ) else : raise e return application . app_id , service_principal . object_id , str ( application_credential )
Create an AAD application and service principal
Create an AAD application and service principal
"""
        Create an AAD application and service principal
        :param credentials: msrestazure.azure_active_directory.AdalAuthentication
        :param tenant_id: str
        :param **application_name: str
    """
credentials
None
tenant_id
None
**application_name
None