Login Authentication 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.
InteractiveLoginAuthentication(force=False, tenant_id=None, cloud=None)
Indicates whether "az login" will be run even if the old "az login" is still valid. The default is False.
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.
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.
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)
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)