Testing for IRC & Channels connection for debugging OAuth Server (because it's better to roll my own for this) internal/auth/oauth.go tests/startup_checks.go More tests to come for debugging Plan to impliment Logging in internal/stoage/logs for internal & UI debugging
47 lines
964 B
Go
47 lines
964 B
Go
package oauth
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
"net/url"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
var (
|
|
clientID = os.Getenv("TWITCH_CLIENT_ID")
|
|
clientSecret = os.Getenv("TWITCH_CLIENT_SECRET")
|
|
redirectURI = "http://localhost:8080/callback"
|
|
|
|
scopes = []string{
|
|
"chat:read",
|
|
"chat:edit",
|
|
"channel:read:subscriptions",
|
|
"user:read:email",
|
|
}
|
|
)
|
|
|
|
type TokenResponse struct {
|
|
AccessToken string `json:"access_token"`
|
|
RefreshToken string `json:"refresh_token"`
|
|
ExpiresIn int `json:"expires_in"`
|
|
Scope []string `json:"scope"`
|
|
TokenType string `json:"token_type"`
|
|
}
|
|
|
|
// start http server for oauth login & callback
|
|
func StartOAuthServer(addr string) error {
|
|
if clientID == "" || clientSecret == "" {
|
|
return fmt.Errorf("TWITCH_CLIENT_ID and TWITCH_CLIENT_SECRET must be set")
|
|
}
|
|
|
|
http.HandleFunc("/", handleIndex)
|
|
http.HandleFunc("/callback", handleCallback)
|
|
|
|
log.Printf("OAuth server listening on %s", addr)
|
|
return http.ListenAndServe(addr, nil)
|
|
}
|
|
|