card-jong-be/controller/utils.go

21 lines
363 B
Go
Raw Normal View History

2024-05-16 21:17:41 +00:00
package controller
import (
"strings"
)
func AuthHeaderIsValid(users *map[string]string, authHeader string) bool {
// (try to) get the Bearer token
reqToken := authHeader
if !strings.HasPrefix(reqToken, "Bearer ") {
return false
}
bearerToken := reqToken[7:]
// Check that the token is in the global map
_, ok := (*users)[bearerToken]
return ok
}