twitch-bot/botEditor.go
Knut Ahlers 4f00beefd0
Allow to issue generic tokens with variable expiry
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2024-11-25 00:41:21 +01: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")
}