fix: inject Bearer token in API proxy
This commit is contained in:
parent
e39d1b9ebd
commit
66eb350564
1 changed files with 5 additions and 0 deletions
5
main.go
5
main.go
|
|
@ -610,6 +610,11 @@ func initials(s string) string {
|
||||||
func apiProxyHandler(w http.ResponseWriter, r *http.Request) {
|
func apiProxyHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
target, _ := url.Parse("http://127.0.0.1:8080")
|
target, _ := url.Parse("http://127.0.0.1:8080")
|
||||||
proxy := httputil.NewSingleHostReverseProxy(target)
|
proxy := httputil.NewSingleHostReverseProxy(target)
|
||||||
|
// Inject Bearer token for authelia-api auth
|
||||||
|
token := os.Getenv("AUTHELIA_SECRET")
|
||||||
|
if token != "" {
|
||||||
|
r.Header.Set("Authorization", "Bearer "+token)
|
||||||
|
}
|
||||||
r.URL.Path = strings.TrimPrefix(r.URL.Path, "/api")
|
r.URL.Path = strings.TrimPrefix(r.URL.Path, "/api")
|
||||||
proxy.ServeHTTP(w, r)
|
proxy.ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue