From 58c1c1794eeec1c0b36c46f543cc4a7b6fd54d57 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 23 Dec 2022 01:44:56 +0100 Subject: [PATCH] fix(backend): optionally support "Bearer " prefix in auth header --- backend/server/auth.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/server/auth.go b/backend/server/auth.go index 50d1226..6113ba3 100644 --- a/backend/server/auth.go +++ b/backend/server/auth.go @@ -3,6 +3,7 @@ package server import ( "context" "net/http" + "strings" "codeberg.org/u1f320/pronouns.cc/backend/server/auth" "github.com/go-chi/render" @@ -11,7 +12,7 @@ import ( // maybeAuth is a globally-used middleware. func (s *Server) maybeAuth(next http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) { - token := r.Header.Get("Authorization") + token := strings.TrimPrefix(r.Header.Get("Authorization"), "Bearer ") if token == "" { next.ServeHTTP(w, r) return