InteractiveLoginAuthentication Class

Manages authentication and acquires an authorization token in interactive login workflows.

Interactive login authentication is suitable for local experimentation on your own computer, and is the default authentication model when using Azure Machine Learning SDK. For example, when working locally in a Jupyter notebook, the interactive login authentication process opens a browser window opens to prompt for credentials if credentials don't already exist.

Class Interactive Login Authentication constructor.

This constructor will prompt the user to login, then it will save the credentials for any subsequent attempts. If the user is already logged in to azure CLI or have logged in before, the constructor will load the existing credentials without prompt. When this python process is running in Azure Notebook service, the constructor will attempt to use the "connect to azure" feature in Azure Notebooks. If this python process is running on a Notebook VM, the constructor will attempt to use MSI auth.

Inheritance
InteractiveLoginAuthentication

Constructor

InteractiveLoginAuthentication(force=False, tenant_id=None, cloud=None)

Parameters

force
bool
default value: False

Indicates whether "az login" will be run even if the old "az login" is still valid. The default is False.

tenant_id
str
default value: None

The tenant ID to login in to. This is can be used to specify a specific tenant when you have access to multiple tenants. If unspecified, the default tenant will be used.

cloud
str
default value: None

The name of the target cloud. Can be one of "AzureCloud", "AzureChinaCloud", or "AzureUSGovernment". If no cloud is specified, any configured default from the Azure CLI is used. If no default is found, "AzureCloud" is used.

force
bool
Required

Indicates whether "az login" will be run even if the old "az login" is still valid. The default is False.

tenant_id
str
Required

The tenant ID to login in to. This is can be used to specify a specific tenant when you have access to multiple tenants. If unspecified, the default tenant will be used.

cloud
str
Required

The name of the target cloud. Can be one of "AzureCloud", "AzureChinaCloud", or "AzureUSGovernment". If no cloud is specified, any configured default from the Azure CLI is used. If no default is found, "AzureCloud" is used.

Remarks

The constructor of the class will prompt you to login. The constructor then will save the credentials for any subsequent attempts. If you are already logged in with the Azure CLI or have logged-in before, the constructor will load the existing credentials without prompt.


   from azureml.core.authentication import InteractiveLoginAuthentication

   interactive_auth = InteractiveLoginAuthentication()
   auth_header = interactive_auth.get_authentication_header()
   print(auth_header)

You can also initiate an interactive loging using the from_config method of the Workspace class.

When this Python process is running in Azure Notebook service, the constructor will attempt to use the "connect to azure" feature in Azure Notebooks.

If this Python process is running on a Notebook VM, the constructor will attempt to use MSI authentication.

In some use cases you may need to specify a tenant ID. For example, when you are accessing a subscription as a guest to a tenant that is not your default, you will need to specify the tenant ID of the Azure Active Directory you're using as shown in the following example.


   from azureml.core.authentication import InteractiveLoginAuthentication

   interactive_auth = InteractiveLoginAuthentication(tenant_id="my-tenant-id")

   ws = Workspace(subscription_id="my-subscription-id",
                  resource_group="my-ml-rg",
                  workspace_name="my-ml-workspace",
                  auth=interactive_auth)

Full sample is available from https://github.com/Azure/MachineLearningNotebooks/blob/master/how-to-use-azureml/manage-azureml-service/authentication-in-azureml/authentication-in-azureml.ipynb