Added JWT Auth

Wrote my own JWT auth middleware, since I could not get the go-chi middleware to accept a JWKS instead of a certificate.
This commit is contained in:
Annika Merris 2024-02-10 17:18:22 -05:00
parent ac18b94a86
commit b5ea01729b
12 changed files with 336 additions and 132 deletions

29
routes/PowerItemRoutes.go Normal file
View file

@ -0,0 +1,29 @@
package routes
import (
"forgejo.merr.is/annika/isl-api/controllers"
"forgejo.merr.is/annika/isl-api/middlewares"
"github.com/go-chi/chi/v5"
)
func SetupPowerItemRoutes(c controllers.PowerItemController, tokenAuth *middlewares.JWTAuth) *chi.Mux {
r := chi.NewRouter()
r.Get("/", c.GetAll)
r.Get("/asMap", c.GetAllAsMap)
r.Get("/byType/{type:[1-3]}", c.GetAllByType)
r.Get("/byType/{type:[1-3]}/asMap", c.GetAllByTypeAsMap)
ar := chi.NewRouter()
ar.Group(func(r chi.Router) {
r.Use(tokenAuth.Verifier())
r.Use(tokenAuth.Authenticator())
r.Use(tokenAuth.AuthorizeRoles([]string{"add_item"}))
r.Post("/", c.Add)
r.Post("/multiple", c.AddMultiple)
})
r.Mount("/", ar)
return r
}