fix(backend): optionally support "Bearer " prefix in auth header
This commit is contained in:
parent
c7f486ca21
commit
58c1c1794e
1 changed files with 2 additions and 1 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue