ユーザー登録後トリガーは、ユーザーが Database または 接続に追加された後に実行されます。
このフローの Actions はノンブロッキング (非同期) で動作します。つまり、Auth0 パイプラインは Action の実行完了を待たずに処理を続行します。そのため、Action の実行結果は Auth0 トランザクションに影響しません。
post-user-registration トリガーは、Database または Passwordless 接続でユーザーが作成された後に実行されます。このトリガーを使用すると、ユーザーがアプリケーションに登録したことを別のシステムに通知できます。複数のアクションをこのトリガーに紐付けることができ、それらは順番に実行されます。ただし、これらのアクションは非同期で実行されるため、ユーザー登録処理をブロックすることはありません。
/**
* PostUserRegistration フローの実行中に呼び出されるハンドラー。
*
* @param {Event} event - 登録したユーザーとコンテキストに関する詳細。
* @param {PostUserRegistrationAPI} api - ユーザー登録後の動作を変更するために使用できるメソッドを持つインターフェース。
*/
exports.onExecutePostUserRegistration = async (event, api) => {
const { IncomingWebhook } = require("@slack/webhook");
const webhook = new IncomingWebhook(event.secrets.SLACK_WEBHOOK_URL);
const text = `New User: ${event.user.email}`;
const channel = '#some_channel';
webhook.send({ text, channel });
};
この Action を正しく実行するには、SLACK_WEBHOOK_URL という名前のシークレットを含め、@slack/webhook npm パッケージに依存している必要があります。
Auth0 のユーザー ID をリモートシステムに保存する
post-user-registration Action を使用すると、Auth0 のユーザー ID をリモートシステムに保存できます。
/**
* PostUserRegistration フローの実行中に呼び出されるハンドラー。
*
* @param {Event} event - 登録したユーザーとコンテキストに関する詳細。
* @param {PostUserRegistrationAPI} api - ユーザー登録後の動作を変更するために使用できるメソッドを持つインターフェース。
*/
const axios = require("axios");
exports.onExecutePostUserRegistration = async (event, api) => {
await axios.post("https://my-api.exampleco.com/users", { params: { email: event.user.email }});
};
axios のような npm ライブラリを使用するには、そのライブラリを依存関係として Action に追加する必要があります。詳しくは、Write Your First Action の「Add a dependency」セクションをご覧ください。
特定の JA3/JA4 フィンガープリントからのアクセスを拒否する
event.security_context オブジェクトには、現在のトランザクションにおける JA3/JA4 フィンガープリント値が含まれています。
exports.onExecutePreUserRegistration = async (event, api) => {
const clientJa4 = event?.security_context?.ja4;
console.log('[ACTION]', {clientJa4});
const badFingerprints = ['t13d1517h2_8daaf6152771_b6f405a00624','t13d1516h2_8daaf6152771_d8a2da3f94cd'];
if (clientJa4 && badFingerprints.includes(clientJa4)){
api.access.deny('suspicious_tls_fingerprint', 'Your TLS fingerprint has been flagged as suspicious');
}
};