M2Mトリガー

M2Mトリガーは、アクセストークンがクライアントの資格情報フローで発行された場合に実行されます。

Diagram showing the Actions Machine to Machine Flow and when the triggers inside of it run.

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

トリガー

M2M / クライアント資格情報

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

リファレンス

一般的なユースケース

アクセス制御

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

/**
 * @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.");
  }
};

Was this helpful?

/

アクセストークンにカスタムクレームを追加する

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

/**
 * @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);  
};

Was this helpful?

/