fix
This commit is contained in:
@@ -12,7 +12,15 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func NewRouter(auth *handlers.AuthHandler, oauth *handlers.OAuthHandler, consents *handlers.ConsentHandler, positions *handlers.PositionsHandler, svc *services.Service, repo *repositories.OAuthRepository, limiter *services.RateLimiter) *gin.Engine {
|
||||
func NewRouter(
|
||||
auth *handlers.AuthHandler,
|
||||
oauth *handlers.OAuthHandler,
|
||||
consents *handlers.ConsentHandler,
|
||||
positions *handlers.PositionsHandler,
|
||||
svc *services.Service,
|
||||
repo *repositories.OAuthRepository,
|
||||
limiter *services.RateLimiter,
|
||||
) *gin.Engine {
|
||||
r := gin.Default()
|
||||
r.Use(errorMiddleware())
|
||||
|
||||
@@ -20,17 +28,25 @@ func NewRouter(auth *handlers.AuthHandler, oauth *handlers.OAuthHandler, consent
|
||||
{
|
||||
o.GET("/authorize", oauth.Authorize)
|
||||
o.GET("/session/:token", oauth.GetSession)
|
||||
o.POST("/session/login", middleware.RateLimit(limiter, services.LoginRateLimit, middleware.LoginKeyFn), 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)
|
||||
o.POST("/revoke", oauth.Revoke)
|
||||
|
||||
o.POST("/introspect", positions.Introspect)
|
||||
}
|
||||
|
||||
api := r.Group("/api/v1")
|
||||
{
|
||||
a := api.Group("/auth")
|
||||
a.POST("/register", middleware.RateLimit(limiter, services.RegisterRateLimit, middleware.IPKeyFn("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")
|
||||
@@ -41,9 +57,19 @@ func NewRouter(auth *handlers.AuthHandler, oauth *handlers.OAuthHandler, consent
|
||||
me.DELETE("/consent/:clientId", authMiddleware(svc, repo, "profile:consent:delete"), consents.RevokeAppAccess)
|
||||
me.GET("/positions", authMiddleware(svc, repo, "profile:read"), positions.GetMyPositions)
|
||||
|
||||
admin := api.Group("/admin")
|
||||
admin.GET("/positions", authMiddleware(svc, repo), positions.ListPositions)
|
||||
admin.POST("/positions", authMiddleware(svc, repo), positions.UpsertPosition)
|
||||
admin := api.Group("/admin", authMiddleware(svc, repo))
|
||||
{
|
||||
admin.GET("/permissions", positions.ListPermissions)
|
||||
|
||||
admin.GET("/positions", positions.ListPositions)
|
||||
admin.POST("/positions", positions.UpsertPosition)
|
||||
|
||||
admin.POST("/positions/:code/permissions", positions.AddPermissionToPosition)
|
||||
admin.DELETE("/positions/:code/permissions/:permCode", positions.RemovePermissionFromPosition)
|
||||
|
||||
admin.POST("/users/:userId/positions", positions.AssignPosition)
|
||||
admin.DELETE("/users/:userId/positions/:code", positions.RevokePosition)
|
||||
}
|
||||
}
|
||||
|
||||
return r
|
||||
@@ -77,7 +103,15 @@ func authMiddleware(svc *services.Service, repo *repositories.OAuthRepository, r
|
||||
return
|
||||
}
|
||||
|
||||
user, err := svc.GetUserByID(c.Request.Context(), info.UserID)
|
||||
if err != nil {
|
||||
c.Error(models.ErrUnauthorized)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
c.Set("user_id", info.UserID)
|
||||
c.Set("is_admin", user.IsAdmin)
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user