Repository navigation
auth0の導入 - #178
Merged
Merged
auth0の導入#178
Conversation
Collaborator
Author
Auth0導入によるフロー変更ユーザー作成・認証導入前: 導入後: Auth0で認証 → 保護ルートへのアクセス導入前: リクエストヘッダーのトークン → カスタムJWT検証 → ユーザーID取得 導入後: リクエストヘッダーのトークン → Auth0 JWT検証 → 実装詳細Auth0 JWT検証ミドルウェア
ユーザー同期ロジックデータベーススキーマALTER TABLE users ADD COLUMN auth0_sub VARCHAR(255) UNIQUE;
エンドポイント分離の意図
注意点
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
Auth0 JWT認証の実装とユーザー同期エンドポイントの追加
詳細
Auth0導入による変更
1. 認証方式
auth0_subをユニークキーとして使用/auth/syncで自動作成2. エンドポイント構成
/auth/sync(POST): Auth0トークン検証のみ(新規ユーザー同期用)3. ユーザー情報管理
usersテーブルにauth0_subカラム追加familyName,firstName,grade,course主な実装内容
Auth0 JWT検証ミドルウェア
app/interfaces/middleware/auth0.goを新規作成go-jwt-middleware/v2を使用してJWT検証ユーザー同期エンドポイント
POST /auth/sync: Auth0ユーザー情報(sub, email, name, picture)を受け取るauth0_subで検索 → 存在すればuserID返却、なければ新規作成データベース変更
usersテーブルにauth0_sub VARCHAR(255) UNIQUE追加down.sqlでauth0_subカラム削除プロフィール対応
userinfoエンティティにFamilyName,FirstName,Grade,Course追加PUT /userinfo/{userID}でプロフィール更新可能ルート分離
その他
環境変数
注意点
/auth/login,/auth/signupエンドポイントは残存(後で削除予定)auth0_subは UNIQUE 制約付き(重複登録防止)