use Bearer token
All checks were successful
Build / build (push) Successful in 27m13s

This commit is contained in:
Gustavo Maronato 2023-08-30 23:42:55 -03:00
parent 9fa1ee18c0
commit fe90938f51
Signed by: maronato
SSH Key Fingerprint: SHA256:2Gw7kwMz/As+2UkR1qQ/qYYhn+WNh3FGv6ozhoRrLcs

View File

@ -1,6 +1,7 @@
package authmiddleware
import (
"fmt"
"net/http"
"git.maronato.dev/maronato/goshort/internal/errs"
@ -13,7 +14,10 @@ func authenticateViaToken(r *http.Request, tokenService *tokenservice.TokenServi
// Get token from request
value := r.Header.Get(tokenHeader)
if value == "" {
// Use sscanf to remove the "Bearer " prefix, or return an error if it's not present
_, err = fmt.Sscanf(value, "Bearer %s", &value)
if err != nil || value == "" {
return nil, errs.ErrTokenMissing
}