Use authentication middleware
This commit is contained in:
@ -3,6 +3,7 @@ package api
|
||||
import (
|
||||
"encoding/json"
|
||||
"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/logging"
|
||||
"net/http"
|
||||
@ -27,6 +28,9 @@ func NewRouter() http.Handler {
|
||||
// `router.Host(...)` and to HTTPS with `router.Schemes("https")`
|
||||
router = newRouterV1(router)
|
||||
router.Use(logging.HTTPLoggingMiddleware)
|
||||
if auth.InitializeAuthentication() {
|
||||
router.Use(auth.HTTPAuthenticationMiddleware)
|
||||
}
|
||||
return router
|
||||
}
|
||||
|
||||
|
@ -16,8 +16,9 @@ import (
|
||||
var (
|
||||
Config = &configuration{
|
||||
Server: server{
|
||||
Address: "127.0.0.1",
|
||||
Address: "127.0.0.1",
|
||||
Port: 3000,
|
||||
Token: "",
|
||||
TLS: false,
|
||||
CertFile: "",
|
||||
KeyFile: "",
|
||||
@ -43,6 +44,7 @@ var (
|
||||
type server struct {
|
||||
Address string
|
||||
Port int
|
||||
Token string
|
||||
TLS bool
|
||||
CertFile string
|
||||
KeyFile string
|
||||
|
@ -1,6 +1,8 @@
|
||||
server:
|
||||
address: 127.0.0.1
|
||||
port: 3000
|
||||
# If set, this token is required in the X-Poseidon-Token header for each route except /health
|
||||
token: SECRET
|
||||
tls: false
|
||||
certfile: ./poseidon.crt
|
||||
keyfile: ./poseidon.key
|
||||
|
Reference in New Issue
Block a user