次の方法で共有


マネージド ID による認証

適用対象: すべての API Management レベル

authentication-managed-identity ポリシーを使用して、マネージド ID を利用するバックエンド サービスで認証します。 このポリシーでは、指定されたリソースにアクセスするためのアクセス トークンを Microsoft Entra ID から取得するために、基本的にマネージド ID を利用します。 トークンが正常に取得されると、ポリシーは、Authorization スキームを使用してトークンの値を Bearer ヘッダーに設定します。 API Management は、有効期限が切れるまでトークンをキャッシュします。

システムによって割り当てられた ID と、ユーザーが割り当てた複数の ID のいずれかの、どちらを使用してもトークンを要求できます。 client-id が指定されていない場合、システムによって割り当てられた ID が指定されたと見なされます。 client-id 変数が指定されている場合、そのユーザー割り当て ID のトークンが Microsoft Entra ID から要求されます。

ポリシーの要素と子要素を、ポリシー ステートメントで指定された順序で設定します。 API Management ポリシーを設定または編集する方法について説明します。

ポリシー ステートメント

<authentication-managed-identity resource="resource" client-id="clientid of user-assigned identity" output-token-variable-name="token-variable" ignore-error="true|false"/>  

属性

属性 説明 必要 既定値
リソース 文字列 をオンにします。 Microsoft Entra ID におけるターゲット Web API のアプリケーション ID (セキュリティで保護されたリソース)。 ポリシー式を使用できます。 はい 該当なし
クライアントID 文字列 をオンにします。 Microsoft Entra ID のユーザー割り当て ID のクライアント ID。 ポリシー式は使用できません。 いいえ 該当なし。 属性が存在しない場合は、システム割り当て ID が使用されます。
output-token-variable-name 文字列 をオンにします。 string 型のオブジェクトとしてトークン値を受け取るコンテキスト変数の名前。 ポリシー式は使用できません。 いいえ 該当なし
ignore-error Boolean です。 true に設定された場合、アクセス トークンが取得されなかったとしても、ポリシー パイプラインは引き続き実行されます。 いいえ false

使用法

マネージド ID を使用してバックエンド サービスで認証する

<authentication-managed-identity resource="https://graph.microsoft.com"/> 
<authentication-managed-identity resource="https://cognitiveservices.azure.com"/> <!--Azure OpenAI-->
<authentication-managed-identity resource="https://management.azure.com/"/> <!--Azure Resource Manager-->
<authentication-managed-identity resource="https://vault.azure.net"/> <!--Azure Key Vault-->
<authentication-managed-identity resource="https://servicebus.azure.net/"/> <!--Azure Service Bus-->
<authentication-managed-identity resource="https://eventhubs.azure.net/"/> <!--Azure Event Hub-->
<authentication-managed-identity resource="https://storage.azure.com/"/> <!--Azure Blob Storage-->
<authentication-managed-identity resource="https://database.windows.net/"/> <!--Azure SQL-->
<authentication-managed-identity resource="https://signalr.azure.com"/> <!--Azure SignalR-->
<authentication-managed-identity resource="AD_application_id"/> <!--Application (client) ID of your own Azure AD Application-->

マネージド ID を使用し、ヘッダーを手動で設定する

<authentication-managed-identity resource="AD_application_id"
   output-token-variable-name="msi-access-token" ignore-error="false" /> <!--Application (client) ID of your own Azure AD Application-->
<set-header name="Authorization" exists-action="override">
   <value>@("Bearer " + (string)context.Variables["msi-access-token"])</value>
</set-header>

send-request ポリシーでマネージド ID を使用する

<send-request mode="new" timeout="20" ignore-error="false">
    <set-url>https://example.com/</set-url>
    <set-method>GET</set-method>
    <authentication-managed-identity resource="ResourceID"/>
</send-request>

ポリシーに対する処理の詳細については、次のトピックを参照してください。