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

# ユースケース例：パスワードレス認証でのActions

> Actions を使用してパスワードレス認証フローをカスタマイズし、SMS やメール OTP をカスタムプロバイダー経由で送信する方法を説明します。

[Actions](/docs/ja-jp/customize/actions/actions-overview) を使用すると、SMS やメール OTP の配信をカスタムプロバイダー経由で行うことで、[パスワードレス接続](/docs/ja-jp/authenticate/passwordless)を拡張できます。Auth0 Actions を使用すると、認証メッセージの送信に使用する電話・メールサービスを制御できます。

<div id="send-passwordless-email-with-a-custom-email-provider">
  ## カスタムメールプロバイダーを使用してパスワードレスメールを送信する
</div>

ユーザーが[パスワードレスメール接続で認証する](/docs/ja-jp/authenticate/passwordless/authentication-methods/email-otp)と、Auth0 は OTP を配信するために `custom-email-provider` Action をトリガーします。この Action を使用すると、任意のメールサービス経由でメッセージを送信できます。

Action を設定するには、[**Branding > Email Provider**](https://manage.auth0.com/#/templates/provider)に移動し、Use my own email provider をオンにしてから、**Custom Provider** オプションを選択します。カスタムプロバイダーのデフォルトの送信元アドレスを From フィールドに追加します。詳細については、[カスタマイズした Action でメールプロバイダーを設定する](/docs/ja-jp/customize/email/smtp-email-providers/custom/configure-action)を参照してください。

Actions Editor で、次の例を使用します。

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  メールプロバイダーのサービスエンドポイントを Actions コードに追加し、API キーを Actions Editor の Secrets タブに追加する必要があります。
</Callout>

```javascript lines theme={null}
/**
 * Auth0 がパスワードレスのメール OTP を送信する際に呼び出されるハンドラー。
 * @param {Event} event - 通知の詳細。
 * @param {CustomEmailProviderAPI} api - 通知の動作を制御するメソッド。
 */
exports.onExecuteCustomEmailProvider = async (event, api) => {
  try {
    const response = await fetch('https://api.example.com/send-email', {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${event.secrets.API_KEY}`,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        to: event.notification.to,
        from: event.notification.from,
        subject: event.notification.subject,
        html: event.notification.html,
        text: event.notification.text,
      }),
    });

    if (response.status >= 400) {
      api.notification.retry(`Request failed with status: ${response.status}`);
      return;
    }
  } catch (error) {
    api.notification.drop(`Unexpected error: ${error.message}`);
  }
};
```

設定をテストするには、**Send Test Email** を選択します。

利用可能なイベントプロパティについて詳しくは、[Actions Triggers: custom-email-provider - イベントオブジェクト](/docs/ja-jp/customize/email/smtp-email-providers/custom/action-triggers-custom-email-provider-event-object)を参照してください。

<div id="send-passwordless-sms-with-a-custom-phone-provider">
  ## カスタム電話プロバイダーでパスワードレス SMS を送信する
</div>

ユーザーが[パスワードレス SMS 接続を使用して認証を行う](/docs/ja-jp/authenticate/passwordless/authentication-methods/sms-otp)と、Auth0 は OTP を配信するために `custom-phone-provider` Action をトリガーします。この Action を使用すると、任意の SMS プロバイダー経由でメッセージを送信できます。

Action を設定するには、[**Branding > Phone Provider**](https://manage.auth0.com/dashboard/#/phone/templates/phone/provider)に移動します。Phone Message Provider をオンにして、**Custom** オプションを選択します。配信方法として Text、Voice、または両方を選択します。詳細については、[カスタム電話プロバイダーを設定する](/docs/ja-jp/customize/phone-messages/configure-phone-messaging-providers/configure-a-custom-phone-provider)を参照してください。

Actions Editor で、次の例を使用します。

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  電話プロバイダーのサービスエンドポイントを Actions コードに追加し、API キーを Actions Editor の Secrets タブに追加する必要があります。
</Callout>

```javascript lines theme={null}
/**
 * Auth0がパスワードレスSMSのOTPを配信する必要があるときに呼び出されるハンドラー。
 * @param {Event} event - 通知に関する詳細。
 * @param {CustomPhoneProviderAPI} api - 通知の動作を制御するためのメソッド。
 */
exports.onExecuteCustomPhoneProvider = async (event, api) => {
  const response = await fetch('https://api.example.com/messages', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${event.secrets.API_KEY}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      to: event.notification.recipient,
      from: event.notification.from,
      body: event.notification.as_text,
    }),
  });

  if (response.status >= 400) {
    api.notification.retry(`リクエストが次のステータスで失敗しました: ${response.status}`);
  }
};
```

設定をテストするには、**Send Text Message** を選択します。

利用可能なイベントプロパティについて詳しくは、[Actions Triggers: custom-phone-provider - イベントオブジェクト](/docs/ja-jp/customize/phone-messages/configure-phone-messaging-providers/configure-a-custom-phone-provider/actions-triggers-custom-phone-provider-event-object)を参照してください。

<div id="learn-more">
  ## 詳細情報
</div>

* [カスタマイズしたActionでメールプロバイダーを設定する](/docs/ja-jp/customize/email/smtp-email-providers/custom/configure-action)
* [カスタム電話プロバイダーを設定する](/docs/ja-jp/customize/phone-messages/configure-phone-messaging-providers/configure-a-custom-phone-provider)
* [Twilio Verifyを使用してカスタム電話プロバイダーを設定する](/docs/ja-jp/customize/phone-messages/configure-phone-messaging-providers/configure-a-custom-phone-provider/configure-a-custom-phone-provider-with-twilio-verify)
* [パスワードレス接続用のカスタムSMSゲートウェイを設定する](/docs/ja-jp/authenticate/passwordless/authentication-methods/use-sms-gateway-passwordless)
* [パスワードレスにUnified Phone Experienceを使用する](/docs/ja-jp/customize/phone-messages/unified-phone/unified-phone-experience-passwordless)
* [パスワードレス接続のベストプラクティス](/docs/ja-jp/authenticate/passwordless/best-practices)
