Skip to content

Commit

Permalink
Add auth middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiante committed Sep 24, 2023
1 parent 67da943 commit adc4abf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion api/server_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ func (s *Server) SavePURL(ctx *gin.Context) {
func (s *Server) CreateDomain(ctx *gin.Context) {
domain := ctx.Param("domain")

_, err := s.admin.CreateDomain(domain)
user := getAuthenticatedUser(ctx)

_, err := s.admin.CreateDomain(user, domain)
switch true {
case err == nil:
ctx.Status(http.StatusNoContent)
Expand Down
6 changes: 4 additions & 2 deletions api/server_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ func SetupRouting(r gin.IRouter, s *Server) {
swaggerUI.Register(r)
}

isAuthenticated := authenticatedMiddleware(s.user)

webapp.Register(r)

validDomain := validPathVar("domain", regexNamed)
Expand All @@ -40,10 +42,10 @@ func SetupRouting(r gin.IRouter, s *Server) {
admin.Use(validDomain)

// Domain
admin.POST("/domains/:domain", s.CreateDomain)
admin.POST("/domains/:domain", isAuthenticated, s.CreateDomain)

// PURL
admin.PUT("/domains/:domain/purls/:name", validName, s.SavePURL)
admin.PUT("/domains/:domain/purls/:name", isAuthenticated, validName, s.SavePURL)
}

// System endpoints
Expand Down

0 comments on commit adc4abf

Please sign in to comment.