次の方法で共有


ChainedTokenCredential class

getToken メソッドのいずれかがアクセス トークンを返すまで、複数の TokenCredential 実装を順番に試行できるようにします。 詳細については、「ChainedTokenCredential の概要を参照してください。

コンストラクター

ChainedTokenCredential(TokenCredential[])

指定された資格情報を使用して ChainedTokenCredential のインスタンスを作成します。

メソッド

getToken(string | string[], GetTokenOptions)

チェーンされた TokenCredential 実装の 1 つによって返される最初のアクセス トークンを返します。 1 つ以上の資格情報が AuthenticationError をスローし、資格情報がアクセス トークンを返していない場合に、AggregateAuthenticationError をスローします。

このメソッドは、Azure SDK クライアント ライブラリによって自動的に呼び出されます。 このメソッドは直接呼び出すことができますが、トークンのキャッシュとトークンの更新も処理する必要があります。

コンストラクターの詳細

ChainedTokenCredential(TokenCredential[])

指定された資格情報を使用して ChainedTokenCredential のインスタンスを作成します。

new ChainedTokenCredential(sources: TokenCredential[])

パラメーター

sources

TokenCredential[]

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 実装の 1 つによって返される最初のアクセス トークンを返します。 1 つ以上の資格情報が AuthenticationError をスローし、資格情報がアクセス トークンを返していない場合に、AggregateAuthenticationError をスローします。

このメソッドは、Azure SDK クライアント ライブラリによって自動的に呼び出されます。 このメソッドは直接呼び出すことができますが、トークンのキャッシュとトークンの更新も処理する必要があります。

function getToken(scopes: string | string[], options?: GetTokenOptions): Promise<AccessToken>

パラメーター

scopes

string | string[]

トークンがアクセスできるスコープの一覧。

options
GetTokenOptions

この TokenCredential 実装が行う可能性のある要求を構成するために使用されるオプション。

戻り値

Promise<AccessToken>