Skip to content

Commit 09f3183

Browse files
authored
Added X-Authorization header (#10)
1 parent 685ae84 commit 09f3183

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

cmd/tesla-http-api/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,19 @@ func router(next http.Handler) http.Handler {
4545
}
4646
case "api":
4747
if apiTokenEnabled {
48+
// Accept Authorization header or the legacy/custom X-Authorization
4849
token := r.Header.Get("Authorization")
50+
if token == "" {
51+
token = r.Header.Get("X-Authorization")
52+
}
4953
if token != apiToken {
5054
logger.Info("Request to %s from %s \033[31m(invalid token)\033[0m", r.URL.Path, r.Header.Get("X-Forwarded-For"))
5155
http.Error(w, http.StatusText(403), http.StatusForbidden)
5256
return
5357
}
58+
// Remove any provided auth headers so we can inject the Tesla Bearer token cleanly
5459
r.Header.Del("Authorization")
60+
r.Header.Del("X-Authorization")
5561
}
5662

5763
r.Header.Add("Authorization", "Bearer "+tesla.AccessToken)

0 commit comments

Comments
 (0)