mirror of
https://forgejo.merr.is/annika/isl-api.git
synced 2025-12-13 05:30:12 -05:00
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:
parent
ac18b94a86
commit
b5ea01729b
12 changed files with 336 additions and 132 deletions
29
routes/PowerItemRoutes.go
Normal file
29
routes/PowerItemRoutes.go
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue