feat: ci/cd

This commit is contained in:
Giovanni Rezcjikov
2026-03-09 12:50:29 +03:00
parent f4e4fb21e3
commit daaa702dad
21 changed files with 585 additions and 267 deletions
+5 -14
View File
@@ -4,6 +4,7 @@ import (
"strings"
"github.com/dusiburg/kotosoft-id/internal/handlers"
"github.com/dusiburg/kotosoft-id/internal/middleware"
"github.com/dusiburg/kotosoft-id/internal/models"
"github.com/dusiburg/kotosoft-id/internal/repositories"
"github.com/dusiburg/kotosoft-id/internal/services"
@@ -11,7 +12,7 @@ import (
"github.com/google/uuid"
)
func NewRouter(auth *handlers.AuthHandler, oauth *handlers.OAuthHandler, consents *handlers.ConsentHandler, svc *services.Service, repo *repositories.OAuthRepository) *gin.Engine {
func NewRouter(auth *handlers.AuthHandler, oauth *handlers.OAuthHandler, consents *handlers.ConsentHandler, svc *services.Service, repo *repositories.OAuthRepository, limiter *services.RateLimiter) *gin.Engine {
r := gin.Default()
r.Use(errorMiddleware())
@@ -19,7 +20,7 @@ func NewRouter(auth *handlers.AuthHandler, oauth *handlers.OAuthHandler, consent
{
o.GET("/authorize", oauth.Authorize)
o.GET("/session/:token", oauth.GetSession)
o.POST("/session/login", oauth.SessionLogin)
o.POST("/session/login", middleware.RateLimit(limiter, services.LoginRateLimit, middleware.LoginKeyFn), oauth.SessionLogin)
o.POST("/session/attach", oauth.SessionAttach)
o.POST("/session/approve", oauth.SessionApprove)
o.POST("/token", oauth.Token)
@@ -29,7 +30,7 @@ func NewRouter(auth *handlers.AuthHandler, oauth *handlers.OAuthHandler, consent
api := r.Group("/api/v1")
{
a := api.Group("/auth")
a.POST("/register", auth.Register)
a.POST("/register", middleware.RateLimit(limiter, services.RegisterRateLimit, middleware.IPKeyFn("register")), auth.Register)
a.POST("/refresh", auth.Refresh)
me := api.Group("/me")
@@ -65,7 +66,7 @@ func authMiddleware(svc *services.Service, repo *repositories.OAuthRepository, r
return
}
if err, _ := repo.GetOAuthClientByID(c.Request.Context(), info.ClientID); err != nil {
if _, err := repo.GetOAuthClientByID(c.Request.Context(), info.ClientID); err != nil {
c.Error(models.ErrForbidden)
c.Abort()
return
@@ -93,16 +94,6 @@ func errorMiddleware() gin.HandlerFunc {
}
}
func clientAuthFromRequest(c *gin.Context) services.ClientAuth {
if id, secret, ok := c.Request.BasicAuth(); ok {
return services.ClientAuth{ClientID: id, ClientSecret: secret}
}
return services.ClientAuth{
ClientID: c.PostForm("client_id"),
ClientSecret: c.PostForm("client_secret"),
}
}
func bearerToken(c *gin.Context) (string, bool) {
return strings.CutPrefix(c.GetHeader("Authorization"), "Bearer ")
}