feat: Added chapter 8

This commit is contained in:
2024-10-26 15:03:14 +02:00
parent 61beecd4a0
commit 8b7fdf59b5
13 changed files with 289 additions and 5 deletions

View File

@ -81,3 +81,15 @@ func MakeRefreshToken() (string, error) {
hexData := hex.EncodeToString(buffer)
return hexData, nil
}
func GetAPIKey(headers http.Header) (string, error) {
authHeader := headers.Get("Authorization")
if authHeader == "" {
return "", errors.New("authorization header is not set")
}
if !strings.HasPrefix(authHeader, "ApiKey ") {
return "", errors.New("incorrect authorization type, must be of type ApiKey")
}
apiKey := strings.TrimPrefix(authHeader, "ApiKey ")
return strings.TrimSpace(apiKey), nil
}