twitch-bot/botEditor.go
Knut Ahlers f743d56d14
Allow to issue generic tokens with variable expiry
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2024-10-18 10:22:19 +02:00

23 lines
469 B
Go

package main
import (
"fmt"
"net/http"
"github.com/pkg/errors"
)
func getAuthorizationFromRequest(r *http.Request) (string, error) {
token := r.Header.Get("Authorization")
if token == "" {
return "", fmt.Errorf("no authorization provided")
}
_, user, _, _, err := editorTokenService.ValidateLoginToken(token) //nolint:dogsled // Required at other places
if user == "" {
user = "API-User"
}
return user, errors.Wrap(err, "getting authorized user")
}