> ## Documentation Index
> Fetch the complete documentation index at: https://auth0.generaltranslation.app/llms.txt
> Use this file to discover all available pages before exploring further.

# M2Mトリガー

> アクションのM2Mフローと、M2Mフローの一部として実行されるcredentials-exchangeアクショントリガーについて説明します。

M2Mトリガーは、アクセストークンが[クライアントの資格情報フロー](/docs/ja-JP/ja-jp/get-started/authentication-and-authorization-flow/client-credentials-flow)で発行された場合に実行されます。

<Frame>
  <img src="https://mintcdn.com/generaltranslationinc/8DIt0xu_-cUu1jhk/docs/images/ja-jp/cdy7uua7fh8z/1JPl54LFWCUh5StuglZS2o/f651fdcdee208b36c16a3c626177c04b/Machine_to_Machine_Flow__ja-JP_.png?fit=max&auto=format&n=8DIt0xu_-cUu1jhk&q=85&s=046fbc91dc22f88aee40fff4b3bde372" alt="Diagram showing the Actions Machine to Machine Flow and when the triggers inside of it run." width="851" height="215" data-path="docs/images/ja-jp/cdy7uua7fh8z/1JPl54LFWCUh5StuglZS2o/f651fdcdee208b36c16a3c626177c04b/Machine_to_Machine_Flow__ja-JP_.png" />
</Frame>

このフロー内のアクションはブロッキング（同期的）であり、トリガーのプロセスの一部として実行されます。そのため、アクションが完了するまでAuth0パイプラインの他の部分の実行が停止されます。

<div id="triggers">
  ## トリガー
</div>

<div id="m2m-client-credentials">
  ### M2M / クライアント資格情報
</div>

`credentials-exchange`トリガーは、アクセストークンが返される前に実行される関数です。

<div id="references">
  #### リファレンス
</div>

* [イベントオブジェクト](/docs/ja-JP/ja-jp/customize/actions/explore-triggers/machine-to-machine-trigger/credentials-exchange-event-object):クライアント資格情報交換の要求についてコンテキスト情報を提供します。
* [APIオブジェクト](/docs/ja-JP/ja-jp/customize/actions/explore-triggers/machine-to-machine-trigger/credentials-exchange-api-object):フローの動作を変更するためのメソッドが提供されます。

<div id="common-use-cases">
  ## 一般的なユースケース
</div>

<div id="access-control">
  ### アクセス制御
</div>

credentials-exchangeアクションは、カスタムロジックに基づいてアクセストークンを拒否するのに使用できます。

```javascript lines theme={null}
/**
 * @param {Event} event - Details about client credentials grant request.
 * @param {CredentialsExchangeAPI} api - Interface whose methods can be used to change the behavior of client credentials grant.
 */
exports.onExecuteCredentialsExchange = async (event, api) => {
  if (event.request.geoip.continentCode === "NA") {
    api.access.deny('invalid_request', "Access from North America is not allowed.");
  }
};
```

<div id="add-custom-claims-to-the-access-token">
  ### アクセストークンにカスタムクレームを追加する
</div>

credentials-exchangeアクションは、アクセストークンにカスタムクレームを追加するのに使用できます。

```javascript lines theme={null}
/**
 * @param {Event} event - Details about client credentials grant request.
 * @param {CredentialsExchangeAPI} api - Interface whose methods can be used to change the behavior of client credentials grant.
 */
exports.onExecuteCredentialsExchange = async (event, api) => {
  api.accessToken.setCustomClaim("https://my-api.exampleco.com/request-ip", event.request.ip);  
};
```

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  名前空間のある、URI形式のカスタムクレームを使用することを強くお勧めします。名前空間のあるカスタムクレームと名前空間のないカスタムクレームについては、「 [カスタムクレームを作成する](/docs/ja-JP/ja-jp/secure/tokens/json-web-tokens/create-custom-claims)」をお読みください。
</Callout>
