Expect bearer prefix in authorization header
This commit is contained in:
parent
f330279e05
commit
d0e52760d9
|
|
@ -29,8 +29,10 @@ func LoadConfig() *Config {
|
||||||
Ip: os.Getenv("BIND_IP"),
|
Ip: os.Getenv("BIND_IP"),
|
||||||
AuthUsername: os.Getenv("AUTH_USERNAME"),
|
AuthUsername: os.Getenv("AUTH_USERNAME"),
|
||||||
AuthPassword: os.Getenv("AUTH_PASSWORD"),
|
AuthPassword: os.Getenv("AUTH_PASSWORD"),
|
||||||
AuthKey: os.Getenv("SENSOR_AUTH_KEY"),
|
AuthKey: os.Getenv("AUTH_KEY"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Crash when any auth* param is empty
|
||||||
|
|
||||||
return &config
|
return &config
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,10 @@ func LoginAuthMiddleware(server *app.Server) gin.HandlerFunc {
|
||||||
}
|
}
|
||||||
|
|
||||||
func KeyAuthMiddleware(server *app.Server) gin.HandlerFunc {
|
func KeyAuthMiddleware(server *app.Server) gin.HandlerFunc {
|
||||||
|
keyWithBearer := "Bearer " + server.Config.AuthKey
|
||||||
|
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
if c.GetHeader("authorization") != server.Config.AuthKey {
|
if c.GetHeader("authorization") != keyWithBearer {
|
||||||
c.AbortWithStatus(http.StatusUnauthorized)
|
c.AbortWithStatus(http.StatusUnauthorized)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue