mirror of
https://github.com/SecurityBrewery/catalyst.git
synced 2025-12-06 23:32:47 +01:00
Add simple auth (#186)
This commit is contained in:
43
auth/server.go
Normal file
43
auth/server.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
|
||||
"github.com/SecurityBrewery/catalyst/database"
|
||||
)
|
||||
|
||||
func Server(config *Config, catalystDatabase *database.Database, jar *Jar) *chi.Mux {
|
||||
server := chi.NewRouter()
|
||||
|
||||
server.Get("/config", hasOIDC(config))
|
||||
|
||||
if config.OIDCAuthEnable {
|
||||
server.Get("/callback", callback(config, jar))
|
||||
server.Get("/oidclogin", redirectToOIDCLogin(config, jar))
|
||||
}
|
||||
if config.SimpleAuthEnable {
|
||||
server.Post("/login", login(catalystDatabase, jar))
|
||||
}
|
||||
server.Post("/logout", logout())
|
||||
|
||||
return server
|
||||
}
|
||||
|
||||
func hasOIDC(config *Config) func(writer http.ResponseWriter, request *http.Request) {
|
||||
return func(writer http.ResponseWriter, request *http.Request) {
|
||||
b, err := json.Marshal(map[string]any{
|
||||
"simple": config.SimpleAuthEnable,
|
||||
"oidc": config.OIDCAuthEnable,
|
||||
})
|
||||
if err != nil {
|
||||
writer.WriteHeader(http.StatusInternalServerError)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
_, _ = writer.Write(b)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user