InteractiveLoginAuthentication 类

管理身份验证,并获取交互式登录工作流中的授权令牌。

交互式登录身份验证适用于自己计算机上的本地试验,它也是使用 Azure 机器学习 SDK 时的默认身份验证模型。 例如,在本地 Jupyter 笔记本中操作时,交互式登录身份验证过程会打开一个浏览器窗口,提示你输入凭据(如果还没有凭据)。

类交互式登录身份验证构造函数。

此构造函数将提示用户登录,然后保存凭据以供后续尝试使用。 如果用户已登录到 Azure CLI 或之前已登录,则构造函数将在不提示的情况下加载现有凭据。 当此 python 进程在 Azure Notebook 服务中运行时,构造函数将尝试使用 Azure Notebooks 中的“连接到 azure”功能。 如果此 python 进程在 Notebook VM 上运行,构造函数将尝试使用 MSI 身份验证。

继承
InteractiveLoginAuthentication

构造函数

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

参数

force
bool
默认值: False

指示是否将运行“az login”,即使旧的“az login”仍然有效。 默认值为 False。

tenant_id
str
默认值: None

要登录到的租户 ID。 当你有权访问多个租户时,此项可用于指定特定租户。 如未指定,将使用默认租户。

cloud
str
默认值: None

目标云的名称。 可以是“AzureCloud”、“AzureChinaCloud”或“AzureUSGovernment”之一。 如未指定云,则使用 Azure CLI 中任何配置的默认值。 如未找到默认值,则使用“AzureCloud”。

force
bool
必需

指示是否将运行“az login”,即使旧的“az login”仍然有效。 默认值为 False。

tenant_id
str
必需

要登录到的租户 ID。 当你有权访问多个租户时,此项可用于指定特定租户。 如未指定,将使用默认租户。

cloud
str
必需

目标云的名称。 可以是“AzureCloud”、“AzureChinaCloud”或“AzureUSGovernment”之一。 如未指定云,则使用 Azure CLI 中任何配置的默认值。 如未找到默认值,则使用“AzureCloud”。

注解

类的构造函数会提示你登录。 然后,构造函数将保存凭据以用于任何后续尝试。 如果已使用 Azure CLI 登录或之前已登录,则构造函数将加载现有凭据,不会提示登录。


   from azureml.core.authentication import InteractiveLoginAuthentication

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

还可以使用 Workspace 类的 from_config 方法启动交互式登录。

如果此 Python 进程正在 Azure 笔记本服务中运行,则构造函数将尝试使用 Azure Notebooks 中的“连接到 Azure”功能。

如果此 Python 进程正在笔记本 VM 上运行,则构造函数将尝试使用 MSI 身份验证。

在某些用例中,你可能需要指定租户 ID。 例如,当你作为来宾访问非默认租户的订阅时,你将需要指定所使用的 Azure Active Directory 的租户 ID,如以下示例中所示。


   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)

完整示例可从 https://github.com/Azure/MachineLearningNotebooks/blob/master/how-to-use-azureml/manage-azureml-service/authentication-in-azureml/authentication-in-azureml.ipynb 获取