kinda working
This commit is contained in:
23
internal/auth/auth.go
Normal file
23
internal/auth/auth.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var ErrNoAuthHeaderIncluded = errors.New("no authorization header included")
|
||||
|
||||
// GetAPIKey -
|
||||
func GetAPIKey(headers http.Header) (string, error) {
|
||||
authHeader := headers.Get("Authorization")
|
||||
if authHeader == "" {
|
||||
return "", ErrNoAuthHeaderIncluded
|
||||
}
|
||||
splitAuth := strings.Split(authHeader, " ")
|
||||
if len(splitAuth) < 2 || splitAuth[0] != "ApiKey" {
|
||||
return "", errors.New("malformed authorization header")
|
||||
}
|
||||
|
||||
return splitAuth[1], nil
|
||||
}
|
||||
Reference in New Issue
Block a user