> ## 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.

# データベース接続でのパスワードレス認証

> 新規または既存のデータベース接続で、完全なパスワードレス認証を設定する方法を紹介します。

export const ReleaseStageNotice = ({feature, stage, plans, contact, terms}) => {
  const stageTextMap = {
    "beta": "Beta",
    "ea": "早期アクセス"
  };
  const stageText = stageTextMap[stage] || "製品リリース段階";
  const prsLink = "/docs/troubleshoot/product-lifecycle/product-release-stages";
  const linkify = (text, url) => {
    return <a href={url} target="_blank" rel="noreferrer" class="link">{text}</a>;
  };
  const includeDetails = (plans, contact, terms) => {
    const hasDetails = terms || plans || contact;
    if (!hasDetails) return null;
    return <span data-as="p">
            {plans && <>この機能は{linkify(`${plans}プラン`, "https://auth0.com/pricing")}でご利用いただけます。 </>}
            {contact && "参加をご希望の場合は、" + contact + "までお問い合わせください。 "}
            {terms && <>この機能を使用することにより、Oktaの該当する無料トライアル規約および{linkify("Master Subscription Agreement", "https://www.okta.com/legal")}に同意したものとみなされます。</>}
        </span>;
  };
  return <Warning>
            <span data-as="p">
                <strong>{feature}機能は現在、{linkify(stageText, prsLink)}です。</strong>
            </span>

            {includeDetails(plans, contact, terms)}
        </Warning>;
};

<ReleaseStageNotice feature="データベース接続でのパスワードレス認証" stage="ea" contact="support" terms="true" />

Auth0 では、[データベース接続](/docs/ja-jp/authenticate/database-connections)でメールおよび電話ベースのパスワードレス認証を直接設定できます。ワンタイムパスワード (OTP) 認証用に別の接続を作成しなくても、データベース接続から直接パスワードレスログインを提供できます。これにより、実装の複雑さが軽減され、エンドユーザーのログイン体験がよりシンプルになります。API ベースの認証については、[Authentication API を使用したデータベース接続でのパスワードレス認証](/docs/ja-jp/authenticate/database-connections/auth-api-passwordless-db-connections)をお読みください。

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  データベース接続でのパスワードレスは、クラシックログインではサポートされていません。API でデータベース接続のパスワードレス認証を使用するには、[Authentication API を使用したデータベース接続でのパスワードレス認証](/docs/ja-jp/authenticate/database-connections/auth-api-passwordless-db-connections)をお読みください。
</Callout>

<div id="how-it-works">
  ## 仕組み
</div>

Auth0 では、ユーザーを OTP 認証で確認する [Identifier-First Authentication](/docs/ja-jp/authenticate/login/auth0-universal-login/identifier-first) アプローチを採用しています。

1. エンドユーザーは、ログインに使用する識別子を入力します。パスワードレス認証は、Auth0 Universal Login または [Authentication API](/docs/ja-jp/authenticate/database-connections/auth-api-passwordless-db-connections) を介して利用できます。
2. Auth0 は、データベース接続で設定されている各識別子に対応する認証方法を確認します。
3. ユーザーには、`default_method` と利用可能な認証方法に基づいて、最適な選択肢が表示されます (たとえば、メールまたは電話で OTP を受け取る、またはパスワードを入力する、など) 。
4. OTP が認証方法として選択された場合、Auth0 はユーザーのメールアドレスまたは電話番号にコードを送信します。
5. ユーザーがコードを入力すると認証されます。パスキーを設定している場合は、段階的なパスキー登録が求められます。

<Card title="始める前に">
  * テナントで [Identifier-First Authentication Profile](/docs/ja-jp/authenticate/login/auth0-universal-login/identifier-first) を使用するよう設定してください。
  * 電話ベースの OTP (SMS または Voice) を使用する予定がある場合は、[**Branding > Phone Provider**](https://manage.auth0.com/#/phone/templates/phone/provider) にある [Unified Phone Experience](/docs/ja-jp/customize/phone-messages/unified-phone/configure-unified-phone) 設定を有効にする必要があります。
  * データベース接続で [Attributes](/docs/ja-jp/authenticate/database-connections/activate-and-configure-attributes-for-flexible-identifiers) を有効にする必要があります。
  * 既存の (レガシーな) パスワードレス接続を、データベース接続でのパスワードレス認証と併用する予定があり、既存のパスワードレス接続で Unified Phone Provider を使用する設定を行いたくない場合:
    1. [**Auth0 Dashboard > Authentication > Passwordless**](https://manage.auth0.com/#/connections/passwordless) に移動します。
    2. SMS の **Configure** を選択します。
    3. **Use Tenant-Level Messaging Provider** 設定が無効になっていることを確認します。
</Card>

<div id="configure-attributes-identifiers">
  ## 属性 (識別子) を設定する
</div>

データベース接続でメールまたは電話番号を使ったパスワードレス認証を設定する場合は、まず、サインアップ時とログイン時にエンドユーザーに入力してもらう属性を決める必要があります。

識別子の種類と、それに対応する認証方法を確認してください。

| 識別子   | 認証方法                 |
| ----- | -------------------- |
| メール   | パスワード、Email OTP、パスキー |
| 電話    | パスワード、Phone OTP、パスキー |
| ユーザー名 | パスワード                |

メール識別子と電話識別子では、パスワードが**有効化**されていない場合、サインアップ時に OTP 検証を有効にしておく必要があります。また、サインアップ時にはメール属性と電話属性を任意項目として設定できるため、ユーザーはメールのみ、または電話番号のみでサインアップできます。

ユーザーが Email OTP で認証すると、そのユーザーのプロファイルでは `email_verified` が自動的に `true` に設定されます。ユーザーが Phone OTP で認証すると、`phone_verified` が自動的に `true` に設定されます。

<Warning>
  エンドユーザーにパスキーで認証させる場合は、メールや電話などの代替の認証方法を**必ず**設定しておく必要があります。パスキーのみの認証には対応していません。
</Warning>

詳しくは、[Flexible Identifiers の属性を有効化して設定する](/docs/ja-jp/authenticate/database-connections/activate-and-configure-attributes-for-flexible-identifiers)を参照してください。

<div id="create-a-new-database-connection">
  ## 新しいデータベース接続を作成する
</div>

既存のデータベース接続がない場合は、Auth0 Dashboard または Management API を使用して作成します。

<Tabs>
  <Tab title="Auth0 Dashboard" icon="browser">
    1. [**Auth0 Dashboard > Authentication > Database**](https://manage.auth0.com/#/connections/database) に移動し、**Create DB Connection** を選択して接続を作成します。
    2. 接続に一意の名前を入力します。
    3. エンドユーザーがログインまたはサインアップに使用する属性を 1 つ以上選択します。
    4. 認証方法を 1 つ以上選択します。これらの方法は、接続の作成後にさらに設定できます。
    5. 公開エンドポイント経由でユーザーがサインアップできないようにするには、**Disable Sign Ups** をオンにします。
    6. この接続をサードパーティアプリケーションで使用する場合は、**Promote Connection to Domain Level** をオンにします。
    7. **Create** を選択します。

    完全なパスワードレス接続にするには、さらに次の手順を行います。

    1. 新しい接続で、**Attributes** タブを選択します。
    2. 識別子として Username を無効にするには、**Configure** を選択し、**Use Username as Identifier** をオフにします。
    3. Email と Phone の識別子を設定するには、**Configure** を選択します。

    * Email 属性では、Verification Methods で **One-Time Password (OTP)** を選択し、完全なパスワードレス構成にするため **Verify email on sign up** を有効にします。これにより `email_verified` が自動的に設定され、ユーザーはログイン時とサインアップ時に常に OTP の入力を求められます。

    4. **保存** を選択します。

    5. 選択した識別子に対応する認証方法を設定します。`phone_otp` および/または `email_otp` が設定されていない場合、パスワードは無効にできません。

    6. Password settings で **Policy** を選択し、次の項目を **Block** に設定します。

       * Login での Password
       * Signup での Password
       * セルフサービスの change password (自動的に更新されます)

    7. **Support users without a password** をオンにします。
           <Callout icon="file-lines" color="#0EA5E9" iconType="regular">
             **Support users without a password** をオンにしないと、エラーが発生する場合があります。
           </Callout>

    8. **保存** を選択します。表示された prompt で、既存のユーザーに影響する可能性があることを理解したうえで **Continue** を選択します。

    9. **アプリケーション** タブに移動し、アプリケーションまたは API でこの接続を有効にします。
  </Tab>

  <Tab title="Management API" icon="code">
    <Callout icon="file-lines" color="#0EA5E9" iconType="regular">
      Management API を使用するには、[Management API access token](/docs/ja-jp/secure/tokens/access-tokens/management-api-access-tokens/get-management-api-access-tokens-for-production) が必要です。
    </Callout>

    [Create a Connection](https://auth0.com/docs/api/management/v2/connections/post-connections) エンドポイントを呼び出します。`default_method` オプションを使用して、各識別子の最初の認証方法を設定します。

    ```bash expandable lines theme={null}
    curl --location 'https://YOUR_AUTH0_TENANT/api/v2/connections' \
    --header 'Authorization: Bearer YOUR_MANAGEMENT_API_TOKEN' \
    --header 'Accept: application/json, text/plain, */*' \
    --header 'Content-Type: application/json' \
    --data '{
      "name": "YOUR_CONNECTION_NAME",
      "strategy": "auth0",
      "is_domain_connection": false,
      "options": {
        "disable_signup": false,
        "attributes": {
          "email": {
            "identifier": {
              "active": true,
              "default_method": "email_otp"
            },
            "profile_required": true,
            "signup": {
              "status": "required",
              "verification": {
                "active": true
              }
            },
            "verification_method": "otp",
            "unique": true
          },
          "phone_number": {
            "identifier": {
              "active": true,
              "default_method": "password"
            },
            "profile_required": true,
            "signup": {
              "status": "required",
              "verification": {
                "active": true
              }
            }
          },
          "username": {
            "identifier": {
              "active": true
            },
            "profile_required": true,
            "signup": {
              "status": "required"
            },
            "validation": {
              "min_length": 1,
              "max_length": 15,
              "allowed_types": {
                "email": false,
                "phone_number": false
              }
            }
          }
        },
        "authentication_methods": {
          "password": {
            "enabled": true
          },
          "passkey": {
            "enabled": false
          },
          "email_otp": {
            "enabled": true
          },
          "phone_otp": {
            "enabled": true
          }
        }
      }
    }'
    ```
  </Tab>
</Tabs>

<div id="update-existing-connections">
  ## 既存の接続を更新する
</div>

既存のデータベース接続がある場合は、Auth0 Dashboard または Management API でパスワードレスの設定を更新します。

<Tabs>
  <Tab title="Auth0 Dashboard" icon="browser">
    1. **接続を開く**: [**Auth0 Dashboard > Authentication > Database**](https://manage.auth0.com/#/connections/database) に移動し、更新する接続を選択します。
    2. **Attributes を有効化する**: **Attributes** タブで **Activate** を選択し、新しい Attributes Configuration を有効化します。
    3. **Email 属性と Phone 属性を追加する**: **+ Add Attributes** を選択し、まだ追加されていない場合は Email と Phone Number を追加します。

           <Callout icon="file-lines" color="#0EA5E9" iconType="regular">
             完全なパスワードレス (OTP) 接続では、`username` 識別子 はサポートされていません。
           </Callout>
    4. **OTP 認証方法を有効にする**: **Authentication Methods** タブで以下を設定します。
       * Phone を **Allow** Phone OTP に設定し、変更を保存します。
       * Email を **Allow** Email OTP に設定し、変更を保存します。
    5. **パスワード認証をブロックする**: Password settings で **Policy** を選択し、以下の項目を **Block** に設定します。

       * Password on Login
       * Password on Signup
       * Self-service change password

       **Support users without a password** をオンにします。

           <Callout icon="file-lines" color="#0EA5E9" iconType="regular">
             **Support users without a password** をオンにしないと、エラーが発生する場合があります。
           </Callout>
    6. **保存**: **保存** を選択します。
  </Tab>

  <Tab title="Management API" icon="code">
    <Callout icon="file-lines" color="#0EA5E9" iconType="regular">
      Management API を使用するには、[Management API access token](/docs/ja-jp/secure/tokens/access-tokens/get-management-api-access-tokens-for-production) が必要です。
    </Callout>

    [Update a connection](https://auth0.com/docs/api/management/v2/connections/patch-connections-by-id) エンドポイントを呼び出します。最初の認証方法を設定するには、`default_method` オプションを追加します。Email 属性には `password` または `email_otp` を設定します。Phone 属性には `password` または `phone_otp` を設定します。

    ```bash theme={null}
    curl -L -X PATCH "https://YOUR_AUTH0_TENANT/api/v2/connections/<connection_id>" \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer YOUR_MANAGEMENT_API_TOKEN" \
    -d '{
      "options": {
        "passwordPolicy": "none",
        "authentication_methods": {
          "password": { "enabled": true },
          "passkey": { "enabled": true },
          "email_otp": { "enabled": true },
          "phone_otp": { "enabled": true }
        },
        "attributes": {
          "email": {
            "signup": {
              "status": "required",
              "verification": { "active": true }
            },
            "unique": true,
            "identifier": {
              "active": true,
              "default_method": "email_otp"
            },
            "profile_required": true,
            "verification_method": "otp"
          },
          "phone_number": {
            "signup": {
              "status": "required",
              "verification": { "active": true }
            },
            "identifier": {
              "active": true,
              "default_method": "phone_otp"
            },
            "profile_required": true
          }
        }
      }
    }'
    ```
  </Tab>
</Tabs>

<div id="use-auth0-actions">
  ## Auth0 Actionsを使用する
</div>

データベース接続におけるパスワードレス認証要素についてさらに詳しく確認するには、Auth0 Actionsを使用して属性を設定します。

<div id="post-login-trigger">
  ### Post-login トリガー
</div>

`post-login` トリガーは、ユーザーの認証後、認可サーバーがトークンを返す前に実行されます。[Auth0 Dashboard > Actions > Triggers > Post Login](https://manage.auth0.com/#/actions/flows) の `event.authentication` オブジェクトでは、次のメソッドを利用できます。

| Method        | Parameter | Description                               |
| ------------- | --------- | ----------------------------------------- |
| メール OTP       | `email`   | ユーザーを第一認証要素として認証するために使用されるメール OTP。        |
| SMS による電話 OTP | `sms`     | ユーザーを第一認証要素として認証するために使用される電話 OTP (SMS) 。  |
| 音声通話による電話 OTP | `tel`     | ユーザーを第一認証要素として認証するために使用される電話 OTP (音声通話) 。 |
| パスワード         | `pwd`     | ユーザーを第一認証要素として認証するために使用されるパスワード。          |

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  ユーザーがメール OTP または電話 OTP で認証されると、`email_verified` と `phone_verified` はユーザープロファイルに自動的に設定されます。以前に post-login Action を使ってこれらのフラグを手動で設定していた場合は、その回避策を削除できます。
</Callout>

`event.authentication` は、次の目的で使用します。

* ユーザーが完了したパスワードレスの認証要素 (`email`、`sms`、`tel`、または `pwd`) を検出する
* 認証方法に基づいてトークンにカスタムクレームを追加する
* ユーザーがどのように認証したかに応じて、条件付きでロジックを実行する

<div id="example">
  #### 例
</div>

次の例では、`event.authentication.methods` を読み取り、ユーザーがどのパスワードレス認証要素で認証を完了したかを判別して、それを ID トークンのカスタムクレームとして追加します。

```javascript theme={null}
exports.onExecutePostLogin = async (event, api) => {
  if (!event.authentication?.methods || event.authentication.methods.length === 0) {
    return;
  }

  if (event.connection.name !== 'YOUR_AUTH0_CONNECTION') {
    return;
  }

  const firstFactor = event.authentication.methods[0];

  if (firstFactor.name === 'email') {
    api.idToken.setCustomClaim('https://your-app.com/auth_method', 'email_otp');
  } else if (firstFactor.name === 'sms' || firstFactor.name === 'tel') {
    api.idToken.setCustomClaim('https://your-app.com/auth_method', 'phone_otp');
  } else if (firstFactor.name === 'pwd') {
    api.idToken.setCustomClaim('https://your-app.com/auth_method', 'password');
  }
};
```

<div id="post-challenge-trigger">
  ### Post-challenge トリガー
</div>

`post-challenge` トリガーは、ユーザーがパスワードリセット、電話番号のバリデーション、MFA などのチャレンジを完了した後に実行されます。[Auth0 Dashboard > Actions > トリガー > password-reset-post-challenge](https://manage.auth0.com/#/actions/flows) の `event.authentication` オブジェクトでは、次の属性を利用できます。

| 属性    | パラメーター         | 説明                                |
| ----- | -------------- | --------------------------------- |
| Email | `email`        | Email OTP またはマジックリンクによるパスワードリセット。 |
| Phone | `phone_number` | Phone OTP によるパスワードリセット。           |

<div id="example">
  #### 例
</div>

次の例では、`event.authentication.methods` を参照して、どのパスワードレス認証要素でチャレンジが完了したかを判定し、その情報を ID トークンのカスタムクレームとして追加します。

```javascript theme={null}
exports.onExecutePostChallenge = async (event, api) => {
  if (!event.authentication?.methods || event.authentication.methods.length === 0) {
    return;
  }

  if (event.connection.name !== 'YOUR_AUTH0_CONNECTION') {
    return;
  }

  const firstFactor = event.authentication.methods[0];

  if (firstFactor.name === 'email') {
    api.idToken.setCustomClaim('https://your-app.com/challenge_method', 'email_otp');
  } else if (firstFactor.name === 'phone_number') {
    api.idToken.setCustomClaim('https://your-app.com/challenge_method', 'phone_otp');
  }
};
```

<div id="benefits">
  ## 利点
</div>

* **実装の簡素化:** 設定・管理する接続の数を減らせます。データベース接続とあわせてソーシャル/フェデレーション接続を使用する場合を除き、アカウントリンクは不要です。
* **ユーザーエクスペリエンスの向上**: Universal Login の同じ identifier-first エクスペリエンス内で、メールベースおよび電話ベースの OTP、パスワード、パスキー、ソーシャル/フェデレーションログインを組み合わせて提供できます。
* **柔軟なサインアップフロー**: サインアップ時にメール属性と電話属性を任意に設定できるため、ユーザーはメールだけ、または電話番号だけでサインアップできます。モバイルファーストやメールのみのエクスペリエンスに最適です。
* **音声OTP**: Unified Phone Experience で設定すると、音声OTP を第1認証要素として利用できます。

<div id="learn-more">
  ## 詳細はこちら
</div>

* [パスワードレス認証](/docs/ja-jp/authenticate/passwordless)
* [データベース接続でのパスワードレスログインに Authentication API を使用する](/docs/ja-jp/authenticate/database-connections/auth-api-passwordless-db-connections)
* [パスワードレスデータベース接続での暗黙的な Signup と Login](/docs/ja-jp/authenticate/database-connections/implicit-signup-database-connections)
* [パスワードレス接続の制限事項](/docs/ja-jp/authenticate/passwordless/passwordless-connection-limitations)
* [パスワードレス接続のベストプラクティス](/docs/ja-jp/authenticate/passwordless/best-practices)
* [Flexible Identifiers の属性を有効化して設定する](/docs/ja-jp/authenticate/database-connections/activate-and-configure-attributes-for-flexible-identifiers)
