mirror of
https://github.com/pocket-id/pocket-id.git
synced 2025-12-16 18:23:08 +03:00
19 lines
419 B
Go
19 lines
419 B
Go
package utils
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
// BearerAuth returns the value of the bearer token in the Authorization header if present
|
|
func BearerAuth(r *http.Request) (string, bool) {
|
|
const prefix = "bearer "
|
|
|
|
authHeader := r.Header.Get("Authorization")
|
|
if len(authHeader) >= len(prefix) && strings.ToLower(authHeader[:len(prefix)]) == prefix {
|
|
return authHeader[len(prefix):], true
|
|
}
|
|
|
|
return "", false
|
|
}
|