Skip to content

Commit

Permalink
fix: ignore basic auth header (#13473)
Browse files Browse the repository at this point in the history
  • Loading branch information
naltatis committed Apr 18, 2024
1 parent f483f2c commit 54c7440
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions server/http_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package server
import (
"encoding/json"
"net/http"
"strings"
"time"

"github.com/evcc-io/evcc/util/auth"
Expand Down Expand Up @@ -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]
}

// read from cookie
if cookie, _ := r.Cookie(authCookieName); cookie != nil {
return cookie.Value
}

return tokenString
return ""
}

// authStatusHandler login status (true/false) based on jwt token. Error if admin password is not configured
Expand Down

0 comments on commit 54c7440

Please sign in to comment.