Use authentication middleware

This commit is contained in:
sirkrypt0
2021-04-29 17:52:27 +02:00
parent 99ee8c6dfb
commit 5891a8c48b
3 changed files with 9 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package api
import ( import (
"encoding/json" "encoding/json"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"gitlab.hpi.de/codeocean/codemoon/poseidon/api/auth"
"gitlab.hpi.de/codeocean/codemoon/poseidon/api/dto" "gitlab.hpi.de/codeocean/codemoon/poseidon/api/dto"
"gitlab.hpi.de/codeocean/codemoon/poseidon/logging" "gitlab.hpi.de/codeocean/codemoon/poseidon/logging"
"net/http" "net/http"
@ -27,6 +28,9 @@ func NewRouter() http.Handler {
// `router.Host(...)` and to HTTPS with `router.Schemes("https")` // `router.Host(...)` and to HTTPS with `router.Schemes("https")`
router = newRouterV1(router) router = newRouterV1(router)
router.Use(logging.HTTPLoggingMiddleware) router.Use(logging.HTTPLoggingMiddleware)
if auth.InitializeAuthentication() {
router.Use(auth.HTTPAuthenticationMiddleware)
}
return router return router
} }

View File

@ -16,8 +16,9 @@ import (
var ( var (
Config = &configuration{ Config = &configuration{
Server: server{ Server: server{
Address: "127.0.0.1", Address: "127.0.0.1",
Port: 3000, Port: 3000,
Token: "",
TLS: false, TLS: false,
CertFile: "", CertFile: "",
KeyFile: "", KeyFile: "",
@ -43,6 +44,7 @@ var (
type server struct { type server struct {
Address string Address string
Port int Port int
Token string
TLS bool TLS bool
CertFile string CertFile string
KeyFile string KeyFile string

View File

@ -1,6 +1,8 @@
server: server:
address: 127.0.0.1 address: 127.0.0.1
port: 3000 port: 3000
# If set, this token is required in the X-Poseidon-Token header for each route except /health
token: SECRET
tls: false tls: false
certfile: ./poseidon.crt certfile: ./poseidon.crt
keyfile: ./poseidon.key keyfile: ./poseidon.key