你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
ChainedTokenCredential class
允许按顺序尝试多个 TokenCredential
实现,直到 getToken 方法之一返回访问令牌。 有关详细信息,请参阅 ChainedTokenCredential 概述。
构造函数
Chained |
使用给定凭据创建 ChainedTokenCredential 的实例。 |
方法
get |
返回链接 此方法由 Azure SDK 客户端库自动调用。 可以直接调用此方法,但还必须处理令牌缓存和令牌刷新。 |
构造函数详细信息
ChainedTokenCredential(TokenCredential[])
使用给定凭据创建 ChainedTokenCredential 的实例。
new ChainedTokenCredential(sources: TokenCredential[])
参数
- sources
TokenCredential
要按顺序尝试的实现。
示例用法:
import { ClientSecretCredential, ChainedTokenCredential } from "@azure/identity";
const tenantId = "<tenant-id>";
const clientId = "<client-id>";
const clientSecret = "<client-secret>";
const anotherClientId = "<another-client-id>";
const anotherSecret = "<another-client-secret>";
const firstCredential = new ClientSecretCredential(tenantId, clientId, clientSecret);
const secondCredential = new ClientSecretCredential(tenantId, anotherClientId, anotherSecret);
const credentialChain = new ChainedTokenCredential(firstCredential, secondCredential);
方法详细信息
getToken(string | string[], GetTokenOptions)
返回链接 TokenCredential
实现之一返回的第一个访问令牌。 当一个或多个凭据引发 AuthenticationError 且未返回访问令牌时,引发 AggregateAuthenticationError。
此方法由 Azure SDK 客户端库自动调用。 可以直接调用此方法,但还必须处理令牌缓存和令牌刷新。
function getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken>
参数
- scopes
-
string | string[]
令牌有权访问的范围列表。
- options
- GetTokenOptions
用于配置此 TokenCredential
实现可能发出的任何请求的选项。
返回
Promise<AccessToken>