mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-14 02:52:42 +00:00
21 lines
503 B
Go
21 lines
503 B
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/Luzifer/twitch-bot/v3/pkg/twitch"
|
|
)
|
|
|
|
func getAuthorizationFromRequest(r *http.Request) (string, *twitch.Client, error) {
|
|
token := r.Header.Get("Authorization")
|
|
if token == "" {
|
|
return "", nil, errors.New("no authorization provided")
|
|
}
|
|
|
|
tc := twitch.New(cfg.TwitchClient, cfg.TwitchClientSecret, token, "")
|
|
|
|
_, user, err := tc.GetAuthorizedUser(r.Context())
|
|
return user, tc, errors.Wrap(err, "getting authorized user")
|
|
}
|