fix(backend): optionally support "Bearer " prefix in auth header

This commit is contained in:
Sam 2022-12-23 01:44:56 +01:00
parent c7f486ca21
commit 58c1c1794e
No known key found for this signature in database
GPG Key ID: B4EF20DDE721CAA1
1 changed files with 2 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package server
import ( import (
"context" "context"
"net/http" "net/http"
"strings"
"codeberg.org/u1f320/pronouns.cc/backend/server/auth" "codeberg.org/u1f320/pronouns.cc/backend/server/auth"
"github.com/go-chi/render" "github.com/go-chi/render"
@ -11,7 +12,7 @@ import (
// maybeAuth is a globally-used middleware. // maybeAuth is a globally-used middleware.
func (s *Server) maybeAuth(next http.Handler) http.Handler { func (s *Server) maybeAuth(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) { fn := func(w http.ResponseWriter, r *http.Request) {
token := r.Header.Get("Authorization") token := strings.TrimPrefix(r.Header.Get("Authorization"), "Bearer ")
if token == "" { if token == "" {
next.ServeHTTP(w, r) next.ServeHTTP(w, r)
return return