Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lindacmsheard/010932f7d3b13246cf340e5f1804d5e6 to your computer and use it in GitHub Desktop.
Save lindacmsheard/010932f7d3b13246cf340e5f1804d5e6 to your computer and use it in GitHub Desktop.

Using Device Login with Azure ML when working with multiple tenants.

The Device login routine used by the AML Python SDK uses the default tenant associated with the login account. This can create issues when working with AML instances in other tenants.

Use the simple login if your AML workspace is within your default tenant. Use the alternative login to force login into a specific tenant.

Simple login to workspace:

This uses the config.json file in the directory structure of the local system. For an AML-provisioned compute VM, this file is located at the root /config.json. If you get an error here as a result of logging into the wrong tenant, use the alternative below.

from azureml.core import Workspace
ws.Workspace.from_config()

Alternative login to workspace:

When working with multiple tenants, use the following to avoid difficulty as a result of your default login tenant being prioritised. This code explicitly specifies the tenant to log in to, and does not use the config.json file.

from azureml.core.authentication import InteractiveLoginAuthentication

Set the workspace parameters:

  1. Find your tenant id by clicking your name or profile photo in the top right corner of the Azure portal, then select switch directory
  2. Find the remaining parameters in the config.json file associated with your AML workspace (downloadable from the portal)
mytenant = "<your tenant id>"
mysub = "<your subscription id>"
myrg = "<your resource group>"
wsname = "<your workspacename>"

Trigger the interactive login

auth = InteractiveLoginAuthentication(force=True, tenant_id=mytenant)

use the get() method instead of the from_config() method.

ws = Workspace.get(wsname, auth, subscription_id=mysub, resource_group=myrg)

Reference Links

  1. Find the configuration variables for your AML workspace in your config.json file, downloadable from the portal
  2. Interactive Login Authentication
  3. Workpace.get() method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment