你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

@azure/ms-rest-nodeauth package

ApplicationTokenCertificateCredentials
ApplicationTokenCredentials
AzureCliCredentials

通过 Azure CLI 检索令牌来描述凭据。

DeviceTokenCredentials
MSIAppServiceTokenCredentials

提供有关应用服务环境中的托管服务标识令牌凭据的信息。

MSITokenCredentials

提供有关托管服务标识令牌凭据的信息。 此对象只能用于获取使用托管服务标识在 Azure 中预配的虚拟机上的令牌。

MSIVmTokenCredentials

提供有关 Azure 中预配的虚拟机上的托管服务标识令牌凭据的信息。

TokenCredentialsBase
UserTokenCredentials

接口

AuthResponse

描述身份验证响应。

AzureTokenCredentialsOptions

描述 servicePrincipal/secret 身份验证的可选参数。

CliAccessToken

描述从 Azure CLI 检索的访问令牌。

InteractiveLoginOptions

介绍交互式身份验证的可选参数。

LinkedSubscription

提供有关在身份验证过程中发现的订阅的信息。 此类型的结构与订阅对象不同,订阅对象通过向 ResourceManager API 发出请求。

LinkedUser

从身份验证角度提供有关用户的信息。

ListAllSubscriptionOptions

介绍可通过 Azure CLI 列出所有订阅/帐户时提供的选项。

LoginWithAuthFileOptions

描述使用AuthFile 登录的可选参数。

LoginWithUsernamePasswordOptions

描述用户名/密码身份验证的可选参数。

MSIAppServiceOptions

定义使用 AppService 的 MSI 进行身份验证的可选参数。

MSIOptions

定义使用 MSI 进行身份验证的可选参数。

MSITokenResponse

描述 MSITokenResponse。

MSIVmOptions

定义用于使用 MSI 进行虚拟机身份验证的可选参数。

类型别名

TokenAudience
UserType

提供有关用户类型的信息。 它当前可以是“user”或“servicePrincipal”。

函数

buildTenantList(TokenCredentialsBase, string)

生成 tenantIds 数组。

createAuthenticator(MSITokenCredentials)
interactiveLogin()

提供一个 URL 和代码,该 URL 和代码需要在浏览器中复制和粘贴,并在其中进行身份验证。 如果成功,用户将获取 DeviceTokenCredentials 对象以及与该 userId 关联的所有适用租户的订阅列表。

使用个人帐户时,需要将 domain 参数中的 options 属性设置为该帐户的租户 ID。 否则,生成的凭据将无法访问帐户的资源。

interactiveLogin(InteractiveLoginOptions)
interactiveLogin(InteractiveLoginOptions, (err: Error, credentials: DeviceTokenCredentials, subscriptions: LinkedSubscription[]) => void)
interactiveLogin(any)
interactiveLoginWithAuthResponse(InteractiveLoginOptions)

提供一个 URL 和代码,该 URL 和代码需要在浏览器中复制和粘贴,并在其中进行身份验证。 如果成功,用户将获取 DeviceTokenCredentials 对象以及与该 userId 关联的所有适用租户的订阅列表。

使用个人帐户时,需要将 domain 参数中的 options 属性设置为该帐户的租户 ID。 否则,生成的凭据将无法访问帐户的资源。

loginWithAppServiceMSI()

使用应用服务 MSI 进行身份验证。

loginWithAppServiceMSI(MSIAppServiceOptions)
loginWithAppServiceMSI(MSIAppServiceOptions, Callback<MSIAppServiceTokenCredentials>)
loginWithAppServiceMSI(Callback<MSIAppServiceTokenCredentials>)
loginWithAuthFile()

使用此方法之前,请从 https://github.com/Azure/azure-cli/releases安装 az cli。 然后执行 az ad sp create-for-rbac --sdk-auth > ${yourFilename.json}。 如果要为其他云/环境创建 sp,请执行:

  1. az 云列表
  2. az cloud set –n <环境的名称>
  3. az ad sp create-for-rbac --sdk-auth > auth.json // 使用机密创建 SP
  4. az ad sp create-for-rbac --create-cert --sdk-auth > auth.json // create sp with certificate If the service principal is created then login with service principal info:
  5. az login --service-principal -u <clientId> -p <clientSecret> -t <tenantId>
  6. az account show --sdk-auth > auth.json

使用身份验证文件中提供的服务主体信息进行身份验证。 此方法会将身份验证文件中的 subscriptionId 设置为选项参数或默认的“AZURE_SUBSCRIPTION_ID”用户提供的环境变量。

loginWithAuthFile(LoginWithAuthFileOptions)
loginWithAuthFile(LoginWithAuthFileOptions, (err: Error, credentials: ApplicationTokenCredentials | ApplicationTokenCertificateCredentials, subscriptions: LinkedSubscription[]) => void)
loginWithAuthFile(any)
loginWithAuthFileWithAuthResponse(LoginWithAuthFileOptions)

使用此方法之前,请从 https://github.com/Azure/azure-cli/releases安装 az cli。 然后执行 az ad sp create-for-rbac --sdk-auth > ${yourFilename.json}。 如果要为其他云/环境创建 sp,请执行:

  1. az 云列表
  2. az cloud set –n <环境的名称>
  3. az ad sp create-for-rbac --sdk-auth > auth.json // 使用机密创建 SP
  4. az ad sp create-for-rbac --create-cert --sdk-auth > auth.json // create sp with certificate If the service principal is created then login with service principal info:
  5. az login --service-principal -u <clientId> -p <clientSecret> -t <tenantId>
  6. az account show --sdk-auth > auth.json

使用身份验证文件中提供的服务主体信息进行身份验证。 此方法会将身份验证文件中的 subscriptionId 设置为选项参数或默认的“AZURE_SUBSCRIPTION_ID”用户提供的环境变量。

loginWithServicePrincipalCertificate(string, string, string)

提供 ApplicationTokenCertificateCredentials 对象和与该服务PrincipalId/clientId 关联的所有适用租户的订阅列表。

使用个人帐户时,需要将 domain 参数设置为该帐户的租户的 ID。 否则,生成的凭据将无法访问帐户的资源。

loginWithServicePrincipalCertificate(string, string, string, AzureTokenCredentialsOptions)
loginWithServicePrincipalCertificate(string, string, string, AzureTokenCredentialsOptions, (err: Error, credentials: ApplicationTokenCertificateCredentials, subscriptions: LinkedSubscription[]) => void)
loginWithServicePrincipalCertificate(string, string, string, any)
loginWithServicePrincipalCertificateWithAuthResponse(string, string, string, AzureTokenCredentialsOptions)

提供 ApplicationTokenCertificateCredentials 对象和与该服务PrincipalId/clientId 关联的所有适用租户的订阅列表。

使用个人帐户时,需要将 domain 参数设置为该帐户的租户的 ID。 否则,生成的凭据将无法访问帐户的资源。

loginWithServicePrincipalSecret(string, string, string)

提供 ApplicationTokenCredentials 对象和与该服务PrincipalId/clientId 关联的订阅列表,以及所有适用租户中的订阅列表。

使用个人帐户时,需要将 domain 参数设置为该帐户的租户的 ID。 否则,生成的凭据将无法访问帐户的资源。

loginWithServicePrincipalSecret(string, string, string, AzureTokenCredentialsOptions)
loginWithServicePrincipalSecret(string, string, string, AzureTokenCredentialsOptions, (err: Error, credentials: ApplicationTokenCredentials, subscriptions: LinkedSubscription[]) => void)
loginWithServicePrincipalSecret(string, string, string, any)
loginWithServicePrincipalSecretWithAuthResponse(string, string, string, AzureTokenCredentialsOptions)

提供 ApplicationTokenCredentials 对象和与该服务PrincipalId/clientId 关联的订阅列表,以及所有适用租户中的订阅列表。

使用个人帐户时,需要将 domain 参数设置为该帐户的租户的 ID。 否则,生成的凭据将无法访问帐户的资源。

loginWithUsernamePassword(string, string)

提供 UserTokenCredentials 对象和与该 userId 关联的订阅列表,以及所有适用租户中的该用户 Id。

此方法仅适用于未启用 2FA 的组织 ID,否则请使用交互式登录。

使用个人帐户时,需要将 domain 参数中的 options 属性设置为该帐户的租户 ID。 否则,生成的凭据将无法访问帐户的资源。

loginWithUsernamePassword(string, string, LoginWithUsernamePasswordOptions)
loginWithUsernamePassword(string, string, any)
loginWithUsernamePassword(string, string, LoginWithUsernamePasswordOptions, (err: Error, credentials: UserTokenCredentials, subscriptions: LinkedSubscription[]) => void)
loginWithUsernamePasswordWithAuthResponse(string, string, LoginWithUsernamePasswordOptions)

提供 UserTokenCredentials 对象和与该 userId 关联的订阅列表,以及所有适用租户中的该用户 Id。 此方法仅适用于未启用 2FA 的组织 ID,否则请使用交互式登录。

使用个人帐户时,需要将 domain 参数中的 options 属性设置为该帐户的租户 ID。 否则,生成的凭据将无法访问帐户的资源。

loginWithVmMSI()

使用此方法之前,请从 https://github.com/Azure/azure-cli/releases安装 az cli。 如果已使用 az cli 预配了 Azure 虚拟机并启用了 MSI,则可以使用此方法从 VM 获取身份验证令牌。

若要创建新 VM,请启用 MSI,请执行以下命令:az vm create -g <resource_group_name> -n <vm_name> --assign-identity --image <os_image_name> 注意:上述命令在主机上启用服务终结点,并具有默认端口 50342

若要在已预配的 VM 上启用 MSI,请执行以下命令:az vm --assign-identity -g <resource_group_name> -n <vm_name> --port <custom_port_number>

若要详细了解此命令,请执行:az vm --assign-identity -h

使用 Azure 虚拟机上运行的标识服务进行身份验证。 此方法向 VM 上托管的身份验证服务发出请求,并获取访问令牌。

loginWithVmMSI(MSIVmOptions)
loginWithVmMSI(MSIVmOptions, Callback<MSIVmTokenCredentials>)
loginWithVmMSI(Callback<MSIVmTokenCredentials>)

函数详细信息

buildTenantList(TokenCredentialsBase, string)

生成 tenantIds 数组。

function buildTenantList(credentials: TokenCredentialsBase, apiVersion?: string): Promise<string[]>

参数

credentials
TokenCredentialsBase

凭据。

apiVersion

string

默认值 2016-06-01

返回

Promise<string[]>

解析为 tenantId 数组并拒绝并出现错误的承诺。

createAuthenticator(MSITokenCredentials)

function createAuthenticator(credentials: MSITokenCredentials): Authenticator

参数

credentials
MSITokenCredentials

返回

interactiveLogin()

提供一个 URL 和代码,该 URL 和代码需要在浏览器中复制和粘贴,并在其中进行身份验证。 如果成功,用户将获取 DeviceTokenCredentials 对象以及与该 userId 关联的所有适用租户的订阅列表。

使用个人帐户时,需要将 domain 参数中的 options 属性设置为该帐户的租户 ID。 否则,生成的凭据将无法访问帐户的资源。

function interactiveLogin(): Promise<DeviceTokenCredentials>

返回

如果回调作为最后一个参数传递,则返回 void,否则返回 Promise。 使用生成的 DeviceTokenCredentials 对象和所有适用租户中的关联订阅列表调用回调。

interactiveLogin(InteractiveLoginOptions)

function interactiveLogin(options: InteractiveLoginOptions): Promise<DeviceTokenCredentials>

参数

返回

interactiveLogin(InteractiveLoginOptions, (err: Error, credentials: DeviceTokenCredentials, subscriptions: LinkedSubscription[]) => void)

function interactiveLogin(options: InteractiveLoginOptions, callback: (err: Error, credentials: DeviceTokenCredentials, subscriptions: LinkedSubscription[]) => void)

参数

callback

(err: Error, credentials: DeviceTokenCredentials, subscriptions: LinkedSubscription[]) => void

interactiveLogin(any)

function interactiveLogin(callback: any)

参数

callback

any

interactiveLoginWithAuthResponse(InteractiveLoginOptions)

提供一个 URL 和代码,该 URL 和代码需要在浏览器中复制和粘贴,并在其中进行身份验证。 如果成功,用户将获取 DeviceTokenCredentials 对象以及与该 userId 关联的所有适用租户的订阅列表。

使用个人帐户时,需要将 domain 参数中的 options 属性设置为该帐户的租户 ID。 否则,生成的凭据将无法访问帐户的资源。

function interactiveLoginWithAuthResponse(options?: InteractiveLoginOptions): Promise<AuthResponse<DeviceTokenCredentials>>

参数

options
InteractiveLoginOptions

表示可选参数的对象。

返回

解析为 AuthResponse 的 Promise,其中包含“凭据”和可选的“订阅”数组,并拒绝并出现错误。

loginWithAppServiceMSI()

使用应用服务 MSI 进行身份验证。

function loginWithAppServiceMSI(): Promise<MSIAppServiceTokenCredentials>

返回

如果回调作为最后一个参数传递,则返回 void,否则返回 Promise。 使用生成的 MSIAppServiceTokenCredentials 对象调用回调。

loginWithAppServiceMSI(MSIAppServiceOptions)

function loginWithAppServiceMSI(options: MSIAppServiceOptions): Promise<MSIAppServiceTokenCredentials>

参数

返回

loginWithAppServiceMSI(MSIAppServiceOptions, Callback<MSIAppServiceTokenCredentials>)

function loginWithAppServiceMSI(options: MSIAppServiceOptions, callback: Callback<MSIAppServiceTokenCredentials>)

参数

callback

Callback<MSIAppServiceTokenCredentials>

loginWithAppServiceMSI(Callback<MSIAppServiceTokenCredentials>)

function loginWithAppServiceMSI(callback: Callback<MSIAppServiceTokenCredentials>)

参数

callback

Callback<MSIAppServiceTokenCredentials>

loginWithAuthFile()

使用此方法之前,请从 https://github.com/Azure/azure-cli/releases安装 az cli。 然后执行 az ad sp create-for-rbac --sdk-auth > ${yourFilename.json}。 如果要为其他云/环境创建 sp,请执行:

  1. az 云列表
  2. az cloud set –n <环境的名称>
  3. az ad sp create-for-rbac --sdk-auth > auth.json // 使用机密创建 SP
  4. az ad sp create-for-rbac --create-cert --sdk-auth > auth.json // create sp with certificate If the service principal is created then login with service principal info:
  5. az login --service-principal -u <clientId> -p <clientSecret> -t <tenantId>
  6. az account show --sdk-auth > auth.json

使用身份验证文件中提供的服务主体信息进行身份验证。 此方法会将身份验证文件中的 subscriptionId 设置为选项参数或默认的“AZURE_SUBSCRIPTION_ID”用户提供的环境变量。

function loginWithAuthFile(): Promise<ApplicationTokenCredentials | ApplicationTokenCertificateCredentials>

返回

如果回调作为最后一个参数传递,则返回 void,否则返回 Promise。 通过生成的 ApplicationTokenCredentials 或 ApplicationTokenCertificateCredentials 对象以及所有适用租户中的关联订阅列表调用回调。

loginWithAuthFile(LoginWithAuthFileOptions)

function loginWithAuthFile(options: LoginWithAuthFileOptions): Promise<ApplicationTokenCredentials | ApplicationTokenCertificateCredentials>

参数

返回

loginWithAuthFile(LoginWithAuthFileOptions, (err: Error, credentials: ApplicationTokenCredentials | ApplicationTokenCertificateCredentials, subscriptions: LinkedSubscription[]) => void)

function loginWithAuthFile(options: LoginWithAuthFileOptions, callback: (err: Error, credentials: ApplicationTokenCredentials | ApplicationTokenCertificateCredentials, subscriptions: LinkedSubscription[]) => void)

参数

callback

(err: Error, credentials: ApplicationTokenCredentials | ApplicationTokenCertificateCredentials, subscriptions: LinkedSubscription[]) => void

loginWithAuthFile(any)

function loginWithAuthFile(callback: any)

参数

callback

any

loginWithAuthFileWithAuthResponse(LoginWithAuthFileOptions)

使用此方法之前,请从 https://github.com/Azure/azure-cli/releases安装 az cli。 然后执行 az ad sp create-for-rbac --sdk-auth > ${yourFilename.json}。 如果要为其他云/环境创建 sp,请执行:

  1. az 云列表
  2. az cloud set –n <环境的名称>
  3. az ad sp create-for-rbac --sdk-auth > auth.json // 使用机密创建 SP
  4. az ad sp create-for-rbac --create-cert --sdk-auth > auth.json // create sp with certificate If the service principal is created then login with service principal info:
  5. az login --service-principal -u <clientId> -p <clientSecret> -t <tenantId>
  6. az account show --sdk-auth > auth.json

使用身份验证文件中提供的服务主体信息进行身份验证。 此方法会将身份验证文件中的 subscriptionId 设置为选项参数或默认的“AZURE_SUBSCRIPTION_ID”用户提供的环境变量。

function loginWithAuthFileWithAuthResponse(options?: LoginWithAuthFileOptions): Promise<AuthResponse<ApplicationTokenCredentials | ApplicationTokenCertificateCredentials>>

参数

options
LoginWithAuthFileOptions

可选参数

返回

解析为 AuthResponse 的 Promise,其中包含“凭据”和可选的“订阅”数组,并拒绝并出现错误。

loginWithServicePrincipalCertificate(string, string, string)

提供 ApplicationTokenCertificateCredentials 对象和与该服务PrincipalId/clientId 关联的所有适用租户的订阅列表。

使用个人帐户时,需要将 domain 参数设置为该帐户的租户的 ID。 否则,生成的凭据将无法访问帐户的资源。

function loginWithServicePrincipalCertificate(clientId: string, certificateStringOrFilePath: string, domain: string): Promise<ApplicationTokenCertificateCredentials>

参数

clientId

string

Active Directory 应用程序客户端 ID 也称为 SPN(ServicePrincipal 名称)。 有关示例,请参阅适用于 .Net Active Directory 快速入门。

certificateStringOrFilePath

string

PEM 编码的证书和私钥或包含该信息的 .pem 文件的绝对文件路径。 例如:

  • CertificateString: “-----BEGIN PRIVATE KEY <-----\nxxxxx>\n----- END PRIVATE KEY-----\n-----BEGIN CERTIFICATE <-----\nyyyyy>\n----- END CERTIFICATE-----\n”
  • CertificateFilePath:.pem 文件的绝对 文件路径。
domain

string

包含此应用程序的域或租户 ID。

返回

如果回调作为最后一个参数传递,则返回 void,否则返回 Promise。 通过生成的 ApplicationTokenCertificateCredentials 对象和所有适用租户中的关联订阅列表调用回调。

loginWithServicePrincipalCertificate(string, string, string, AzureTokenCredentialsOptions)

function loginWithServicePrincipalCertificate(clientId: string, certificateStringOrFilePath: string, domain: string, options: AzureTokenCredentialsOptions): Promise<ApplicationTokenCertificateCredentials>

参数

clientId

string

certificateStringOrFilePath

string

domain

string

返回

loginWithServicePrincipalCertificate(string, string, string, AzureTokenCredentialsOptions, (err: Error, credentials: ApplicationTokenCertificateCredentials, subscriptions: LinkedSubscription[]) => void)

function loginWithServicePrincipalCertificate(clientId: string, certificateStringOrFilePath: string, domain: string, options: AzureTokenCredentialsOptions, callback: (err: Error, credentials: ApplicationTokenCertificateCredentials, subscriptions: LinkedSubscription[]) => void)

参数

clientId

string

certificateStringOrFilePath

string

domain

string

callback

(err: Error, credentials: ApplicationTokenCertificateCredentials, subscriptions: LinkedSubscription[]) => void

loginWithServicePrincipalCertificate(string, string, string, any)

function loginWithServicePrincipalCertificate(clientId: string, certificateStringOrFilePath: string, domain: string, callback: any)

参数

clientId

string

certificateStringOrFilePath

string

domain

string

callback

any

loginWithServicePrincipalCertificateWithAuthResponse(string, string, string, AzureTokenCredentialsOptions)

提供 ApplicationTokenCertificateCredentials 对象和与该服务PrincipalId/clientId 关联的所有适用租户的订阅列表。

使用个人帐户时,需要将 domain 参数设置为该帐户的租户的 ID。 否则,生成的凭据将无法访问帐户的资源。

function loginWithServicePrincipalCertificateWithAuthResponse(clientId: string, certificateStringOrFilePath: string, domain: string, options?: AzureTokenCredentialsOptions): Promise<AuthResponse<ApplicationTokenCertificateCredentials>>

参数

clientId

string

Active Directory 应用程序客户端 ID 也称为 SPN(ServicePrincipal 名称)。 有关示例,请参阅适用于 .Net Active Directory 快速入门。

certificateStringOrFilePath

string

PEM 编码的证书和私钥或包含该信息的 .pem 文件的绝对文件路径。 例如:

  • CertificateString: “-----BEGIN PRIVATE KEY <-----\nxxxxx>\n----- END PRIVATE KEY-----\n-----BEGIN CERTIFICATE <-----\nyyyyy>\n----- END CERTIFICATE-----\n”
  • CertificateFilePath:.pem 文件的绝对 文件路径。
domain

string

包含此应用程序的域或租户 ID。

options
AzureTokenCredentialsOptions

表示可选参数的对象。

返回

解析为 AuthResponse 的 Promise,其中包含“凭据”和可选的“订阅”数组,并拒绝并出现错误。

loginWithServicePrincipalSecret(string, string, string)

提供 ApplicationTokenCredentials 对象和与该服务PrincipalId/clientId 关联的订阅列表,以及所有适用租户中的订阅列表。

使用个人帐户时,需要将 domain 参数设置为该帐户的租户的 ID。 否则,生成的凭据将无法访问帐户的资源。

function loginWithServicePrincipalSecret(clientId: string, secret: string, domain: string): Promise<ApplicationTokenCredentials>

参数

clientId

string

Active Directory 应用程序客户端 ID 也称为 SPN(ServicePrincipal 名称)。 有关示例,请参阅适用于 .Net Active Directory 快速入门。

secret

string

服务主体的应用程序机密。

domain

string

包含此应用程序的域或租户 ID。

返回

如果回调作为最后一个参数传递,则返回 void,否则返回 Promise。 使用生成的 ApplicationTokenCredentials 对象和所有适用租户中的关联订阅列表调用回调。

loginWithServicePrincipalSecret(string, string, string, AzureTokenCredentialsOptions)

function loginWithServicePrincipalSecret(clientId: string, secret: string, domain: string, options: AzureTokenCredentialsOptions): Promise<ApplicationTokenCredentials>

参数

clientId

string

secret

string

domain

string

返回

loginWithServicePrincipalSecret(string, string, string, AzureTokenCredentialsOptions, (err: Error, credentials: ApplicationTokenCredentials, subscriptions: LinkedSubscription[]) => void)

function loginWithServicePrincipalSecret(clientId: string, secret: string, domain: string, options: AzureTokenCredentialsOptions, callback: (err: Error, credentials: ApplicationTokenCredentials, subscriptions: LinkedSubscription[]) => void)

参数

clientId

string

secret

string

domain

string

callback

(err: Error, credentials: ApplicationTokenCredentials, subscriptions: LinkedSubscription[]) => void

loginWithServicePrincipalSecret(string, string, string, any)

function loginWithServicePrincipalSecret(clientId: string, secret: string, domain: string, callback: any)

参数

clientId

string

secret

string

domain

string

callback

any

loginWithServicePrincipalSecretWithAuthResponse(string, string, string, AzureTokenCredentialsOptions)

提供 ApplicationTokenCredentials 对象和与该服务PrincipalId/clientId 关联的订阅列表,以及所有适用租户中的订阅列表。

使用个人帐户时,需要将 domain 参数设置为该帐户的租户的 ID。 否则,生成的凭据将无法访问帐户的资源。

function loginWithServicePrincipalSecretWithAuthResponse(clientId: string, secret: string, domain: string, options?: AzureTokenCredentialsOptions): Promise<AuthResponse<ApplicationTokenCredentials>>

参数

clientId

string

Active Directory 应用程序客户端 ID 也称为 SPN(ServicePrincipal 名称)。 有关示例,请参阅适用于 .Net Active Directory 快速入门。

secret

string

服务主体的应用程序机密。

domain

string

包含此应用程序的域或租户 ID。

options
AzureTokenCredentialsOptions

表示可选参数的对象。

返回

解析为 AuthResponse 的 Promise,其中包含“凭据”和可选的“订阅”数组,并拒绝并出现错误。

loginWithUsernamePassword(string, string)

提供 UserTokenCredentials 对象和与该 userId 关联的订阅列表,以及所有适用租户中的该用户 Id。

此方法仅适用于未启用 2FA 的组织 ID,否则请使用交互式登录。

使用个人帐户时,需要将 domain 参数中的 options 属性设置为该帐户的租户 ID。 否则,生成的凭据将无法访问帐户的资源。

function loginWithUsernamePassword(username: string, password: string): Promise<UserTokenCredentials>

参数

username

string

组织 ID 帐户的用户名。

password

string

组织 ID 帐户的密码。

返回

如果回调作为最后一个参数传递,则返回 void,否则返回 Promise。 使用生成的 UserTokenCredentials 对象和所有适用租户中的关联订阅列表调用回调。

loginWithUsernamePassword(string, string, LoginWithUsernamePasswordOptions)

function loginWithUsernamePassword(username: string, password: string, options: LoginWithUsernamePasswordOptions): Promise<UserTokenCredentials>

参数

username

string

password

string

返回

loginWithUsernamePassword(string, string, any)

function loginWithUsernamePassword(username: string, password: string, callback: any)

参数

username

string

password

string

callback

any

loginWithUsernamePassword(string, string, LoginWithUsernamePasswordOptions, (err: Error, credentials: UserTokenCredentials, subscriptions: LinkedSubscription[]) => void)

function loginWithUsernamePassword(username: string, password: string, options: LoginWithUsernamePasswordOptions, callback: (err: Error, credentials: UserTokenCredentials, subscriptions: LinkedSubscription[]) => void)

参数

username

string

password

string

callback

(err: Error, credentials: UserTokenCredentials, subscriptions: LinkedSubscription[]) => void

loginWithUsernamePasswordWithAuthResponse(string, string, LoginWithUsernamePasswordOptions)

提供 UserTokenCredentials 对象和与该 userId 关联的订阅列表,以及所有适用租户中的该用户 Id。 此方法仅适用于未启用 2FA 的组织 ID,否则请使用交互式登录。

使用个人帐户时,需要将 domain 参数中的 options 属性设置为该帐户的租户 ID。 否则,生成的凭据将无法访问帐户的资源。

function loginWithUsernamePasswordWithAuthResponse(username: string, password: string, options?: LoginWithUsernamePasswordOptions): Promise<AuthResponse<UserTokenCredentials>>

参数

username

string

组织 ID 帐户的用户名。

password

string

组织 ID 帐户的密码。

options
LoginWithUsernamePasswordOptions

表示可选参数的对象。

返回

解析为 AuthResponse 的 Promise,其中包含 credentials 和可选的 subscriptions 数组,并拒绝并出现错误。

loginWithVmMSI()

使用此方法之前,请从 https://github.com/Azure/azure-cli/releases安装 az cli。 如果已使用 az cli 预配了 Azure 虚拟机并启用了 MSI,则可以使用此方法从 VM 获取身份验证令牌。

若要创建新 VM,请启用 MSI,请执行以下命令:az vm create -g <resource_group_name> -n <vm_name> --assign-identity --image <os_image_name> 注意:上述命令在主机上启用服务终结点,并具有默认端口 50342

若要在已预配的 VM 上启用 MSI,请执行以下命令:az vm --assign-identity -g <resource_group_name> -n <vm_name> --port <custom_port_number>

若要详细了解此命令,请执行:az vm --assign-identity -h

使用 Azure 虚拟机上运行的标识服务进行身份验证。 此方法向 VM 上托管的身份验证服务发出请求,并获取访问令牌。

function loginWithVmMSI(): Promise<MSIVmTokenCredentials>

返回

如果回调作为最后一个参数传递,则返回 void,否则返回 Promise。 使用生成的 MSIVmTokenCredentials 对象调用回调。

loginWithVmMSI(MSIVmOptions)

function loginWithVmMSI(options: MSIVmOptions): Promise<MSIVmTokenCredentials>

参数

options
MSIVmOptions

返回

loginWithVmMSI(MSIVmOptions, Callback<MSIVmTokenCredentials>)

function loginWithVmMSI(options: MSIVmOptions, callback: Callback<MSIVmTokenCredentials>)

参数

options
MSIVmOptions
callback

Callback<MSIVmTokenCredentials>

loginWithVmMSI(Callback<MSIVmTokenCredentials>)

function loginWithVmMSI(callback: Callback<MSIVmTokenCredentials>)

参数

callback

Callback<MSIVmTokenCredentials>