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

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

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

> [!WARNING]
>
> **データベース接続でのパスワードレス認証機能は現在、[早期アクセス](/docs/docs/troubleshoot/product-lifecycle/product-release-stages)です。**
>
> 参加をご希望の場合は、supportまでお問い合わせください。
>
> この機能を使用することにより、Oktaの該当する無料トライアル規約および[Master Subscription Agreement](https://www.okta.com/legal)に同意したものとみなされます。

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

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

## 仕組み

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

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

> [card] 始める前に
>
> * テナントで [Identifier-First Authentication Profile](/docs/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/docs/ja-jp/customize/phone-messages/unified-phone/configure-unified-phone) 設定を有効にする必要があります。
> * データベース接続で [Attributes](/docs/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** 設定が無効になっていることを確認します。

## 属性 (識別子) を設定する

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

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

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

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

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

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

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

## 新しいデータベース接続を作成する

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

> [tab] Auth0 Dashboard
>
> 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** をオンにします。
>
>    **Support users without a password** をオンにしないと、エラーが発生する場合があります。
>
> 8. **保存** を選択します。表示された prompt で、既存のユーザーに影響する可能性があることを理解したうえで **Continue** を選択します。
>
> 9. **アプリケーション** タブに移動し、アプリケーションまたは API でこの接続を有効にします。

> [tab] Management API
>
> Management API を使用するには、[Management API access token](/docs/docs/ja-jp/secure/tokens/access-tokens/management-api-access-tokens/get-management-api-access-tokens-for-production) が必要です。
>
> [Create a Connection](/docs/docs/ja-jp/api/management/v2/connections/post-connections) エンドポイントを呼び出します。`default_method` オプションを使用して、各識別子の最初の認証方法を設定します。
>
> > [tab] Auth0 CLI
> >
> > Auth0 CLI を使用していますか？まだ設定していない場合は、このコマンドを実行する前に [CLI セッションをセットアップして認証します](/docs/docs/ja-jp/deploy-monitor/auth0-cli)。
> >
> > ```bash theme={null}
> > auth0 api post "connections" \
> >   --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] cURL
> >
> > ```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
> >       }
> >     }
> >   }
> > }'
> > ```

## 既存の接続を更新する

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

> [tab] Auth0 Dashboard
>
> 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 を追加します。
>
>    完全なパスワードレス (OTP) 接続では、ユーザー名 識別子はサポートされていません。
> 4. **OTP 認証方法を有効にする**: **Authentication Methods** タブで以下を設定します。
>    * Phone を **Allow** Phone OTP に設定し、変更を保存します。
>    * Email を **Allow** Email OTP に設定し、変更を保存します。
> 5. **パスワード認証をブロックする**: Password settings で **Policy** を選択し、以下の項目を **Block** に設定します。
>
>    * Password on Login
>    * Password on サインアップ
>    * Self-service change password
>
>    **Support users without a password** をオンにします。
>
>    **Support users without a password** をオンにしないと、エラーが発生する場合があります。
> 6. **保存**: **保存** を選択します。

> [tab] Management API
>
> Management API を使用するには、[Management API access token](/docs/docs/ja-jp/secure/tokens/access-tokens/get-management-api-access-tokens-for-production) が必要です。
>
> [Update a Connection](/docs/docs/ja-jp/api/management/v2/connections/patch-connections-by-id) エンドポイントを呼び出します。最初の認証方法を設定するには、`default_method` オプションを追加します。Email 属性には `password` または `email_otp` を設定します。Phone 属性には `password` または `phone_otp` を設定します。
>
> > [tab] Auth0 CLI
> >
> > ```bash theme={null}
> > auth0 api patch "connections/<connection_id>" \
> >   --data '{
> >     "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] cURL
> >
> > ```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
> >       }
> >     }
> >   }
> > }'
> > ```

## Auth0 Actionsを使用する

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

### Post-login トリガー

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

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

ユーザーがEmail OTP またはPhone OTP で認証されると、`email_verified` と `phone_verified` はユーザープロファイルに自動的に設定されます。以前に post-login Action を使ってこれらのフラグを手動で設定していた場合は、その回避策を削除できます。

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

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

#### 例

次の例では、`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');
  }
};
```

## 利点

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

## 詳細はこちら

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