2026-05-19 11:00:28 +00:00
|
|
|
|
// Code generated by goctl. DO NOT EDIT.
|
|
|
|
|
|
// goctl 1.10.1
|
|
|
|
|
|
|
|
|
|
|
|
package handler
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"net/http"
|
|
|
|
|
|
"time"
|
|
|
|
|
|
|
2026-05-21 06:45:35 +00:00
|
|
|
|
auth "gateway/internal/handler/auth"
|
2026-05-20 23:51:22 +00:00
|
|
|
|
member "gateway/internal/handler/member"
|
2026-05-19 11:00:28 +00:00
|
|
|
|
normal "gateway/internal/handler/normal"
|
|
|
|
|
|
"gateway/internal/svc"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/zeromicro/go-zero/rest"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
2026-05-20 23:51:22 +00:00
|
|
|
|
server.AddRoutes(
|
|
|
|
|
|
[]rest.Route{
|
|
|
|
|
|
{
|
2026-05-21 06:45:35 +00:00
|
|
|
|
// Email + 密碼登入(ZITADEL ROPG → CloudEP JWT)
|
|
|
|
|
|
Method: http.MethodPost,
|
|
|
|
|
|
Path: "/login",
|
|
|
|
|
|
Handler: auth.LoginHandler(serverCtx),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
// Social 登入 OAuth callback
|
|
|
|
|
|
Method: http.MethodGet,
|
|
|
|
|
|
Path: "/login/social/callback",
|
|
|
|
|
|
Handler: auth.LoginSocialCallbackHandler(serverCtx),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
// Social 登入:建立 login session 並回傳 OAuth URL(不含 invite)
|
|
|
|
|
|
Method: http.MethodPost,
|
|
|
|
|
|
Path: "/login/social/start",
|
|
|
|
|
|
Handler: auth.LoginSocialStartHandler(serverCtx),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
// Email 註冊(建立 ZITADEL + member,寄 registration OTP)
|
|
|
|
|
|
Method: http.MethodPost,
|
|
|
|
|
|
Path: "/register",
|
|
|
|
|
|
Handler: auth.RegisterHandler(serverCtx),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
// 確認 registration OTP 並核發 JWT
|
|
|
|
|
|
Method: http.MethodPost,
|
|
|
|
|
|
Path: "/register/confirm",
|
|
|
|
|
|
Handler: auth.RegisterConfirmHandler(serverCtx),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
// 重寄 registration OTP
|
|
|
|
|
|
Method: http.MethodPost,
|
|
|
|
|
|
Path: "/register/resend",
|
|
|
|
|
|
Handler: auth.RegisterResendHandler(serverCtx),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
// Social 註冊 OAuth callback
|
|
|
|
|
|
Method: http.MethodGet,
|
|
|
|
|
|
Path: "/register/social/callback",
|
|
|
|
|
|
Handler: auth.RegisterSocialCallbackHandler(serverCtx),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
// Social 註冊:建立 session 並回傳 OAuth URL
|
|
|
|
|
|
Method: http.MethodPost,
|
|
|
|
|
|
Path: "/register/social/start",
|
|
|
|
|
|
Handler: auth.RegisterSocialStartHandler(serverCtx),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
// 登出(撤銷 access JWT 及配對 refresh JWT)
|
|
|
|
|
|
Method: http.MethodPost,
|
|
|
|
|
|
Path: "/logout",
|
|
|
|
|
|
Handler: auth.LogoutHandler(serverCtx),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
// ZITADEL id_token 換 CloudEP JWT(企業 SSO)
|
|
|
|
|
|
Method: http.MethodPost,
|
|
|
|
|
|
Path: "/token/exchange",
|
|
|
|
|
|
Handler: auth.TokenExchangeHandler(serverCtx),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
// 以 refresh_token 換發新的 access/refresh token
|
|
|
|
|
|
Method: http.MethodPost,
|
|
|
|
|
|
Path: "/token/refresh",
|
|
|
|
|
|
Handler: auth.TokenRefreshHandler(serverCtx),
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
rest.WithPrefix("/api/v1/auth"),
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
server.AddRoutes(
|
|
|
|
|
|
[]rest.Route{
|
|
|
|
|
|
{
|
|
|
|
|
|
// 取得當前會員 profile(Bearer JWT;本機 dev 可 fallback X-Tenant-ID + X-UID)
|
2026-05-20 23:51:22 +00:00
|
|
|
|
Method: http.MethodGet,
|
|
|
|
|
|
Path: "/me",
|
|
|
|
|
|
Handler: member.GetMemberMeHandler(serverCtx),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
// 更新當前會員 profile
|
|
|
|
|
|
Method: http.MethodPatch,
|
|
|
|
|
|
Path: "/me",
|
|
|
|
|
|
Handler: member.UpdateMemberMeHandler(serverCtx),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
// TOTP 狀態
|
|
|
|
|
|
Method: http.MethodGet,
|
|
|
|
|
|
Path: "/me/totp",
|
|
|
|
|
|
Handler: member.GetTOTPStatusHandler(serverCtx),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
// 解除 TOTP 綁定
|
|
|
|
|
|
Method: http.MethodDelete,
|
|
|
|
|
|
Path: "/me/totp",
|
|
|
|
|
|
Handler: member.DisableTOTPHandler(serverCtx),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
// 重產 TOTP 備援碼
|
|
|
|
|
|
Method: http.MethodPost,
|
|
|
|
|
|
Path: "/me/totp/backup-codes",
|
|
|
|
|
|
Handler: member.RegenerateTOTPBackupCodesHandler(serverCtx),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
// 確認 TOTP 綁定
|
|
|
|
|
|
Method: http.MethodPost,
|
|
|
|
|
|
Path: "/me/totp/enroll-confirm",
|
|
|
|
|
|
Handler: member.ConfirmTOTPEnrollHandler(serverCtx),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
// 開始 TOTP 綁定
|
|
|
|
|
|
Method: http.MethodPost,
|
|
|
|
|
|
Path: "/me/totp/enroll-start",
|
|
|
|
|
|
Handler: member.StartTOTPEnrollHandler(serverCtx),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
// 驗證 TOTP(step-up 測試)
|
|
|
|
|
|
Method: http.MethodPost,
|
|
|
|
|
|
Path: "/me/totp/verify",
|
|
|
|
|
|
Handler: member.VerifyTOTPHandler(serverCtx),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
// 確認業務 email 驗證
|
|
|
|
|
|
Method: http.MethodPost,
|
|
|
|
|
|
Path: "/me/verifications/email/confirm",
|
|
|
|
|
|
Handler: member.ConfirmEmailVerificationHandler(serverCtx),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
// 開始業務 email 驗證
|
|
|
|
|
|
Method: http.MethodPost,
|
|
|
|
|
|
Path: "/me/verifications/email/start",
|
|
|
|
|
|
Handler: member.StartEmailVerificationHandler(serverCtx),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
// 確認業務 phone 驗證
|
|
|
|
|
|
Method: http.MethodPost,
|
|
|
|
|
|
Path: "/me/verifications/phone/confirm",
|
|
|
|
|
|
Handler: member.ConfirmPhoneVerificationHandler(serverCtx),
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
// 開始業務 phone 驗證
|
|
|
|
|
|
Method: http.MethodPost,
|
|
|
|
|
|
Path: "/me/verifications/phone/start",
|
|
|
|
|
|
Handler: member.StartPhoneVerificationHandler(serverCtx),
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
rest.WithPrefix("/api/v1/members"),
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2026-05-19 11:00:28 +00:00
|
|
|
|
server.AddRoutes(
|
|
|
|
|
|
[]rest.Route{
|
|
|
|
|
|
{
|
|
|
|
|
|
// Ping
|
|
|
|
|
|
Method: http.MethodGet,
|
|
|
|
|
|
Path: "/health",
|
|
|
|
|
|
Handler: normal.PingHandler(serverCtx),
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
rest.WithPrefix("/api/v1"),
|
|
|
|
|
|
rest.WithTimeout(3000*time.Millisecond),
|
|
|
|
|
|
)
|
|
|
|
|
|
}
|