認証モジュール概要
概要
認証モジュールは、Trend Viewer API の包括的なユーザー認証および認可機能を提供します。メール/パスワードログイン、Google OAuth、標準メール認証など、複数の認証方法をサポートし、ユーザー登録、パスワードリセット、セッション管理も含まれます。
概要アクティビティ図
---
config:
theme: base
layout: dagre
flowchart:
curve: linear
htmlLabels: true
themeVariables:
edgeLabelBackground: "transparent"
---
flowchart TB
%% Main components
Client[クライアントアプリケーション]
AuthController[AuthController]
AuthService(AuthService)
UserDB[(users)]
RoleDB[(roles)]
SessionDB[(sessions)]
Client --- Step1[
<div style='text-align: center'>
<span style='display: inline-block; background-color: #6699cc !important; color:white; width: 28px; height: 28px; line-height: 28px; border-radius: 50%; font-weight: bold'>1</span>
<p style='margin-top: 8px'>認証リクエストを送信</p>
</div>
]
Step1 --> AuthController
AuthController --- Step2[
<div style='text-align: center'>
<span style='display: inline-block; background-color: #6699cc !important; color:white; width: 28px; height: 28px; line-height: 28px; border-radius: 50%; font-weight: bold'>2</span>
<p style='margin-top: 8px'>リクエストを検証</p>
</div>
]
Step2 --> AuthService
AuthService --- Step3[
<div style='text-align: center'>
<span style='display: inline-block; background-color: #6699cc !important; color:white; width: 28px; height: 28px; line-height: 28px; border-radius: 50%; font-weight: bold'>3</span>
<p style='margin-top: 8px'>ユーザーを認証</p>
</div>
]
Step3 --> UserDB
AuthService --- Step4[
<div style='text-align: center'>
<span style='display: inline-block; background-color: #6699cc !important; color:white; width: 28px; height: 28px; line-height: 28px; border-radius: 50%; font-weight: bold'>4</span>
<p style='margin-top: 8px'>ユーザーロールを確認</p>
</div>
]
Step4 --> RoleDB
AuthService --- Step5[
<div style='text-align: center'>
<span style='display: inline-block; background-color: #6699cc !important; color:white; width: 28px; height: 28px; line-height: 28px; border-radius: 50%; font-weight: bold'>5</span>
<p style='margin-top: 8px'>セッションを作成</p>
</div>
]
Step5 --> SessionDB
AuthService --- Step6[
<div style='text-align: center'>
<span style='display: inline-block; background-color: #6699cc !important; color:white; width: 28px; height: 28px; line-height: 28px; border-radius: 50%; font-weight: bold'>6</span>
<p style='margin-top: 8px'>認証Cookieを作成</p>
</div>
]
Step6 --> AuthController
AuthController --- Step7[
<div style='text-align: center'>
<span style='display: inline-block; background-color: #6699cc !important; color:white; width: 28px; height: 28px; line-height: 28px; border-radius: 50%; font-weight: bold'>7</span>
<p style='margin-top: 8px'>レスポンスを返す</p>
</div>
]
Step7 --> Client
%% Styling
style Client fill:#e6f3ff,stroke:#0066cc,stroke-width:2px
style AuthController fill:#e6f3ff,stroke:#0066cc,stroke-width:2px
style AuthService fill:#f0f8e6,stroke:#339933,stroke-width:2px
style UserDB fill:#ffe6cc,stroke:#ff9900,stroke-width:2px
style RoleDB fill:#ffe6cc,stroke:#ff9900,stroke-width:2px
style SessionDB fill:#ffe6cc,stroke:#ff9900,stroke-width:2px
style Step1 fill:transparent,stroke:transparent,stroke-width:1px
style Step2 fill:transparent,stroke:transparent,stroke-width:1px
style Step3 fill:transparent,stroke:transparent,stroke-width:1px
style Step4 fill:transparent,stroke:transparent,stroke-width:1px
style Step5 fill:transparent,stroke:transparent,stroke-width:1px
style Step6 fill:transparent,stroke:transparent,stroke-width:1px
style Step7 fill:transparent,stroke:transparent,stroke-width:1px
データベース関連テーブルとフィールド
erDiagram
users {
bigint id PK "主キー"
varchar name "ユーザーのフルネーム"
varchar email UK "ユーザーのメールアドレス(一意)"
varchar payment_provider_customer_id "決済プロバイダーの顧客ID"
tinyint status "ユーザーステータス (1: アクティブ, 0: 非アクティブ)"
varchar remember_token "Laravelリメンバートークン"
timestamp created_at "作成タイムスタンプ"
timestamp updated_at "最終更新タイムスタンプ"
timestamp deleted_at "ソフト削除タイムスタンプ"
boolean is_first_login "初回ログインフラグ"
}
groups {
bigint id PK "主キー"
varchar name "グループ名"
text description "グループの説明"
bigint created_by FK "グループを作成したユーザー"
timestamp created_at "作成タイムスタンプ"
timestamp updated_at "最終更新タイムスタンプ"
}
group_members {
bigint id PK "主キー"
bigint group_id FK "グループID"
bigint user_id FK "ユーザーID"
bigint group_role_id FK "グループ内のロールID"
timestamp created_at "作成タイムスタンプ"
timestamp updated_at "最終更新タイムスタンプ"
}
group_roles {
bigint id PK "主キー"
varchar name "ロール名"
text description "ロールの説明"
timestamp created_at "作成タイムスタンプ"
timestamp updated_at "最終更新タイムスタンプ"
}
users ||--o{ group_members : "持つ"
groups ||--o{ group_members : "含む"
group_roles ||--o{ group_members : "定義する"
users ||--o{ groups : "作成する"
モジュール機能
| 機能 | 説明 | エンドポイント |
|---|---|---|
| ユーザーログイン | 標準検証によるメール/パスワード認証 | POST /api/v1/general/auth/login |
| ユーザー登録 | 会社情報を含む新規ユーザーアカウント作成 | POST /api/v1/general/auth/register |
| Google 認証 | OAuth ベースの認証と登録 | POST /api/v1/general/auth/google/register |
| パスワードリセット | メールベースのパスワード回復システム | POST /api/v1/general/auth/forgot |
| ユーザーログアウト | セッション終了と Cookie クリーンアップ | GET /api/v1/general/auth/logout |
追加ノート
- 標準認証: システムは安全な検証による標準メール/パスワード認証を使用
- マルチテナントサポート: ユーザーは異なるロールを持つ複数のグループに所属可能
- セッション管理: IP 追跡とユーザーエージェントログを含む包括的なセッション処理
- レート制限: 認証エンドポイントのセキュリティのために実装
- ソフト削除: データ整合性のためユーザーアカウントはソフト削除される
- 初回ログイントラッキング: 初回ユーザー体験の特別な処理
- メール認証: 登録にはセキュリティ向上のためのメール認証が含まれる