DeviceCodeCredential class
启用身份验证以使用用户可输入 https://microsoft.com/devicelogin的设备代码Microsoft Entra ID。
构造函数
| Device |
使用 Microsoft Entra ID 启动设备代码授权流所需的详细信息创建 DeviceCodeCredential 实例。 将记录一条消息,为用户提供一个代码,在用户转到 https://microsoft.com/devicelogin 后,他们可以使用该代码进行身份验证 开发人员可以通过传递自定义
|
方法
| authenticate(string | string[], Get |
使用 Microsoft Entra ID 进行身份验证,如果成功,则返回访问令牌。 如果身份验证失败,则会引发 CredentialUnavailableError,其中包含失败的详细信息。 如果无法以无提示方式检索令牌,此方法将始终为用户生成质询。 |
| get |
使用 Microsoft Entra ID 进行身份验证,如果成功,则返回访问令牌。 如果身份验证失败,则会引发 CredentialUnavailableError,其中包含失败的详细信息。 如果用户提供了 |
构造函数详细信息
DeviceCodeCredential(DeviceCodeCredentialOptions)
使用 Microsoft Entra ID 启动设备代码授权流所需的详细信息创建 DeviceCodeCredential 实例。
将记录一条消息,为用户提供一个代码,在用户转到 https://microsoft.com/devicelogin 后,他们可以使用该代码进行身份验证
开发人员可以通过传递自定义 userPromptCallback来配置此消息的显示方式:
import { DeviceCodeCredential } from "@azure/identity";
const credential = new DeviceCodeCredential({
tenantId: process.env.AZURE_TENANT_ID,
clientId: process.env.AZURE_CLIENT_ID,
userPromptCallback: (info) => {
console.log("CUSTOMIZED PROMPT CALLBACK", info.message);
},
});
new DeviceCodeCredential(options?: DeviceCodeCredentialOptions)
参数
- options
- DeviceCodeCredentialOptions
用于配置发出身份验证请求的客户端的选项。
方法详细信息
authenticate(string | string[], GetTokenOptions)
使用 Microsoft Entra ID 进行身份验证,如果成功,则返回访问令牌。 如果身份验证失败,则会引发 CredentialUnavailableError,其中包含失败的详细信息。
如果无法以无提示方式检索令牌,此方法将始终为用户生成质询。
function authenticate(scopes: string | string[], options?: GetTokenOptions): Promise<undefined | AuthenticationRecord>
参数
- scopes
-
string | string[]
令牌有权访问的范围列表。
- options
- GetTokenOptions
用于配置此 TokenCredential 实现可能发出的任何请求的选项。
返回
Promise<undefined | AuthenticationRecord>
getToken(string | string[], GetTokenOptions)
使用 Microsoft Entra ID 进行身份验证,如果成功,则返回访问令牌。 如果身份验证失败,则会引发 CredentialUnavailableError,其中包含失败的详细信息。
如果用户提供了 disableAutomaticAuthentication选项,则一旦无法以无提示方式检索令牌,此方法将不会尝试请求用户交互以检索令牌。
function getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken>
参数
- scopes
-
string | string[]
令牌有权访问的范围列表。
- options
- GetTokenOptions
用于配置此 TokenCredential 实现可能发出的任何请求的选项。
返回
Promise<AccessToken>