2020-04-08 08:56:42 +02:00
|
|
|
package route
|
|
|
|
|
|
|
|
import (
|
|
|
|
"forge.cadoles.com/wpetit/hydra-passwordless/internal/config"
|
|
|
|
|
|
|
|
"github.com/go-chi/chi"
|
|
|
|
"github.com/gorilla/csrf"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"gitlab.com/wpetit/goweb/session/gorilla"
|
|
|
|
"gitlab.com/wpetit/goweb/static"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Mount(r *chi.Mux, config *config.Config) error {
|
|
|
|
csrfSecret, err := gorilla.GenerateRandomBytes(32)
|
|
|
|
if err != nil {
|
|
|
|
return errors.Wrap(err, "could not generate CSRF secret")
|
|
|
|
}
|
|
|
|
|
|
|
|
csrfMiddleware := csrf.Protect(
|
|
|
|
csrfSecret,
|
|
|
|
csrf.Secure(false),
|
|
|
|
)
|
|
|
|
|
|
|
|
r.Group(func(r chi.Router) {
|
|
|
|
r.Use(csrfMiddleware)
|
|
|
|
|
|
|
|
r.Get("/login", serveLoginPage)
|
|
|
|
r.Post("/login", handleLoginForm)
|
|
|
|
r.Get("/logout", serveLogoutPage)
|
|
|
|
r.Get("/consent", serveConsentPage)
|
2020-05-20 11:13:14 +02:00
|
|
|
r.Get("/verify", handleVerification)
|
2020-04-08 08:56:42 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
notFoundHandler := r.NotFoundHandler()
|
|
|
|
r.Get("/*", static.Dir(config.HTTP.PublicDir, "", notFoundHandler))
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|