feat: Added chapter 8
This commit is contained in:
1 parent
61beecd4a0
commit
8b7fdf59b5
13 files changed
+289
-5
No files matched your search
@@ -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
|
||||
}
|
||||
Reference in new issue
Block a user