Files
smart-go/internal/auth/http_register.go
T
2026-04-23 18:58:13 +08:00

39 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package auth
import (
"giter.top/smart/internal/auth/handler"
"giter.top/smart/internal/auth/oauth2"
"github.com/gin-gonic/gin"
)
// AuthRoutes 认证相关 HTTPOAuth2、登录)。
type AuthRoutes struct {
bearer gin.HandlerFunc
loginRL gin.HandlerFunc
tokenRL gin.HandlerFunc
oauthH *oauth2.Handler
loginH *handler.LoginHandler
}
// NewAuthRoutes 构造(loginRL/tokenRL 使用 Wire 专用类型,见 wire_provider.go)。
func NewAuthRoutes(bearer gin.HandlerFunc, loginRL LoginRateLimitWire, tokenRL TokenRateLimitWire, oauthH *oauth2.Handler, loginH *handler.LoginHandler) *AuthRoutes {
return &AuthRoutes{
bearer: bearer,
loginRL: gin.HandlerFunc(loginRL),
tokenRL: gin.HandlerFunc(tokenRL),
oauthH: oauthH,
loginH: loginH,
}
}
// Register 实现 server.HttpRoutesOAuth 在根路径,/api/v1 挂 Bearer 与登录。
func (r *AuthRoutes) Register(engine *gin.Engine, apiGroup *gin.RouterGroup) {
apiGroup.Use(r.bearer)
apiGroup.POST("/auth/login", r.loginRL, r.loginH.Login)
apiGroup.POST("/auth/logout", r.loginH.Logout)
engine.GET("/oauth/authorize", r.oauthH.Authorize)
engine.POST("/oauth/token", r.tokenRL, r.oauthH.Token)
engine.POST("/oauth/introspect", r.tokenRL, r.oauthH.Introspect)
}