34 lines
886 B
Go
34 lines
886 B
Go
package api
|
|
|
|
import (
|
|
"forge.cadoles.com/wpetit/hydra-webauthn/internal/config"
|
|
"github.com/go-chi/chi"
|
|
"github.com/go-chi/chi/middleware"
|
|
)
|
|
|
|
func Mount(r *chi.Mux, config *config.Config) error {
|
|
basicAuth := middleware.BasicAuth("Hydra WebAuthn", toCredentials(config.API.Authentication.Accounts))
|
|
|
|
r.Route("/api/v1", func(r chi.Router) {
|
|
r.Use(basicAuth)
|
|
r.Post("/users", CreateUser)
|
|
r.Get("/users/{userID}", GetUser)
|
|
r.Get("/users", ListUsers)
|
|
r.Post("/users/{userID}/registration-link", GenerateRegistrationLink)
|
|
r.Get("/users/{userID}/registration-link", GetRegistrationLink)
|
|
r.Put("/users/{userID}", UpdateUser)
|
|
})
|
|
|
|
return nil
|
|
}
|
|
|
|
func toCredentials(accounts []config.AccountConfig) map[string]string {
|
|
credentials := make(map[string]string, len(accounts))
|
|
|
|
for _, acc := range accounts {
|
|
credentials[acc.Username] = acc.Password
|
|
}
|
|
|
|
return credentials
|
|
}
|