Email認証
このドキュメントは、email-authentication 方式による認証処理の 概要・設定・利用方法 について説明します。
概要
Email認証は、ユーザーのメールアドレスにワンタイムコード(OTP)を送信し、それを使って本人確認を行う認証方式です。
idp-server ではEmail認証機能を以下のパターンで提供します:
- 外部Email認証サービスを利用: 外部APIサービスでコード生成・送信・検証を行う
- SMTP送信: idp-serverでコード生成・検証し、SMTPでメール送信
- HTTP API送信: idp-serverでコード生成・検証し、HTTP APIでメール送信
- テスト用(no-action): 実際のメール送信を行わないテスト設定
Email認証は以下の2つのインタラクションを連続的に実行することで成立します:
email-authentication-challenge: 認証用ワンタイムコードの生成・送信email-authentication: ワンタイムコードの検証
テンプレート機能
メールテンプレートでは以下のプレースホルダーが利用可能です:
{VERIFICATION_CODE}: 生成されたワンタイムコード(6桁数字){EXPIRE_SECONDS}: 有効期限(秒数)
これらのプレースホルダーは、SMTP送信・HTTP API送信・テスト用設定のすべてで共通して使用できます。
設定
Email認証を使用するには、テナントに type = "email" の認証設定を登録する必要があります。
基本構造
すべての認証設定は、統一されたinteractions形式を使用します。Email認証では2つのinteractionを定義します:
- email-authentication-challenge: ワンタイムコード生成・送信
- email-authentication: ワンタイムコード検証
{
"id": "UUID",
"type": "email",
"attributes": {},
"metadata": {
"type": "external",
"description": "Email authentication",
"transaction_id_param": "transaction_id",
"verification_code_param": "verification_code"
},
"interactions": {
"email-authentication-challenge": {
"request": { "schema": {...} },
"execution": { "function": "email_authentication_challenge", "details": {...} },
"response": { "body_mapping_rules": [...] }
},
"email-authentication": {
"request": { "schema": {...} },
"execution": { "function": "email_authentication" },
"response": { "body_mapping_rules": [...] }
}
}
}
Interaction 1: email-authentication-challenge
ワンタイムコードを生成し、メール送信するinteractionです。
Request Schema
{
"request": {
"schema": {
"type": "object",
"properties": {
"email": { "type": "string" },
"template": { "type": "string" }
}
}
}
}
Execution
function: email_authentication_challenge
details設定:
{
"execution": {
"function": "email_authentication_challenge",
"details": {
"function": "no_action",
"sender": "test@gmail.com",
"templates": {
"registration": {
"subject": "[ID Verification] Your signup email confirmation code",
"body": "Hello,\n\nPlease enter the following verification code:\n\n【{VERIFICATION_CODE}】\n\nThis code will expire in {EXPIRE_SECONDS} seconds."
},
"authentication": {
"subject": "[ID Verification] Your login email confirmation code",
"body": "Hello,\n\nPlease enter the following verification code:\n\n【{VERIFICATION_CODE}】\n\nThis code will expire in {EXPIRE_SECONDS} seconds."
}
},
"retry_count_limitation": 5,
"expire_seconds": 300
}
}
}
details.function:
no_action: テスト用(実際のメール送信なし)smtp: SMTP経由でメール送信http_request: HTTP API経由でメール送信
Response
{
"response": {
"body_mapping_rules": [
{ "from": "$.response_body", "to": "*" }
]
}
}
Interaction 2: email-authentication
送信されたワンタイムコードを検証するinteractionです。
Request Schema
{
"request": {
"schema": {
"type": "object",
"properties": {
"verification_code": { "type": "string" }
}
}
}
}
Execution
function: email_authentication
ワンタイムコードの検証を行います。
Response
{
"response": {
"body_mapping_rules": [
{ "from": "$.response_body", "to": "*" }
]
}
}
完全な設定例(no-action)
情報源: config/examples/e2e/test-tenant/authentication-config/email/no-action.json
{
"id": "6f5b0255-8faf-42cf-9f24-4f702386993f",
"type": "email",
"attributes": {},
"metadata": {
"type": "external",
"description": "mocky",
"transaction_id_param": "transaction_id",
"verification_code_param": "verification_code"
},
"interactions": {
"email-authentication-challenge": {
"request": {
"schema": {
"type": "object",
"properties": {
"email": { "type": "string" },
"template": { "type": "string" }
}
}
},
"pre_hook": {},
"execution": {
"function": "email_authentication_challenge",
"details": {
"function": "no_action",
"sender": "test@gmail.com",
"templates": {
"registration": {
"subject": "[ID Verification] Your signup email confirmation code",
"body": "Hello,\n\nPlease enter the following verification code:\n\n【{VERIFICATION_CODE}】\n\nThis code will expire in {EXPIRE_SECONDS} seconds.\n\nIf you did not request this, please contact your administrator.\n\n– IDP Support"
},
"authentication": {
"subject": "[ID Verification] Your login email confirmation code",
"body": "Hello,\n\nPlease enter the following verification code:\n\n【{VERIFICATION_CODE}】\n\nThis code will expire in {EXPIRE_SECONDS} seconds.\n\nIf you did not request this, please contact your administrator.\n\n– IDP Support"
}
},
"retry_count_limitation": 5,
"expire_seconds": 300
}
},
"post_hook": {},
"response": {
"body_mapping_rules": [
{ "from": "$.response_body", "to": "*" }
]
}
},
"email-authentication": {
"request": {
"schema": {
"type": "object",
"properties": {
"verification_code": { "type": "string" }
}
}
},
"pre_hook": {},
"execution": {
"function": "email_authentication"
},
"post_hook": {},
"response": {
"body_mapping_rules": [
{ "from": "$.response_body", "to": "*" }
]
}
}
}
}