fix: ignore basic auth header (#13473)

This commit is contained in:
Michael Geers 2024-04-18 06:13:01 +02:00 • committed by GitHub
parent f483f2c74b
commit 54c7440769
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,6 +3,7 @@ package server
import (
"encoding/json"
"net/http"
"strings"
"time"
"github.com/evcc-io/evcc/util/auth"
@ -55,14 +56,19 @@ func updatePasswordHandler(auth auth.Auth) http.HandlerFunc {
// read jwt from header and cookie
func jwtFromRequest(r *http.Request) string {
tokenString := r.Header.Get("Authorization")
if tokenString == "" {
if cookie, _ := r.Cookie(authCookieName); cookie != nil {
tokenString = cookie.Value
}
// read from header
authHeader := r.Header.Get("Authorization")
splitToken := strings.Split(authHeader, "Bearer ")
if len(splitToken) == 2 {
return splitToken[1]
}
return tokenString
// read from cookie
if cookie, _ := r.Cookie(authCookieName); cookie != nil {
return cookie.Value
}
return ""
}
// authStatusHandler login status (true/false) based on jwt token. Error if admin password is not configured