2021-09-22 13:36:45 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-06-16 15:43:37 +00:00
|
|
|
"fmt"
|
2021-09-22 13:36:45 +00:00
|
|
|
"net/http"
|
|
|
|
|
2021-11-25 22:48:16 +00:00
|
|
|
"github.com/pkg/errors"
|
2021-09-22 13:36:45 +00:00
|
|
|
)
|
|
|
|
|
2024-06-16 15:43:37 +00:00
|
|
|
func getAuthorizationFromRequest(r *http.Request) (string, error) {
|
2021-10-22 15:09:39 +00:00
|
|
|
token := r.Header.Get("Authorization")
|
|
|
|
if token == "" {
|
2024-06-16 15:43:37 +00:00
|
|
|
return "", fmt.Errorf("no authorization provided")
|
2021-10-22 15:09:39 +00:00
|
|
|
}
|
2021-09-22 13:36:45 +00:00
|
|
|
|
2024-06-16 15:43:37 +00:00
|
|
|
_, user, _, _, err := editorTokenService.ValidateLoginToken(token) //nolint:dogsled // Required at other places
|
|
|
|
|
|
|
|
if user == "" {
|
|
|
|
user = "API-User"
|
|
|
|
}
|
2021-09-22 13:36:45 +00:00
|
|
|
|
2024-06-16 15:43:37 +00:00
|
|
|
return user, errors.Wrap(err, "getting authorized user")
|
2021-10-22 15:09:39 +00:00
|
|
|
}
|