util

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SpotifyAuthURL is the URL to Spotify Accounts Service's OAuth2 endpoint.
	SpotifyAuthURL = "https://accounts.spotify.com/authorize"

	//nolint:gosec // Mistakenly flagging an authorization URL
	// SpotifyTokenURL is the URL to the Spotify Accounts Service's OAuth2
	// token endpoint.
	SpotifyTokenURL = "https://accounts.spotify.com/api/token"
	// SpotifyUserScope is the set of permissions required to access the necessary
	// Spotify APIs
	SpotifyUserScope = "user-modify-playback-state user-read-playback-state user-read-email"
	// TwitchUserScope is the set of permissions required to access the necessary
	// Twitch APIs
	TwitchUserScope = "channel:manage:redemptions"
)

Variables

This section is empty.

Functions

func GenerateAuthURL

func GenerateAuthURL(host, path string, config *AuthConfig) string

func GetFromEnv

func GetFromEnv(key string) (string, error)

GetFromEnv tries to read an environment variable by key, and if: 1. the key does not exist: return an error 2. the key exists but the value is empty: return an error 3. the key exists AND the value is non-empty: return the value

func GetFromEnvOrDefault

func GetFromEnvOrDefault(key, def string) string

GetFromEnvOrDefault tries to get the environment variable by the given key, and if the var is empty/undefined, it returns the supplied default value instead.

func GetNewSpotifyClient

func GetNewSpotifyClient(ctx context.Context, a *AuthConfig, token *oauth2.Token) *spotify.Client

func GetNewTwitchClient

func GetNewTwitchClient(a *AuthConfig) (*helix.Client, error)

func GetUserIDFromRequest

func GetUserIDFromRequest(r *http.Request) (string, error)

func RefreshSpotifyToken

func RefreshSpotifyToken(ctx context.Context, a *AuthConfig, token *oauth2.Token) (*oauth2.Token, error)

Types

type AuthConfig

type AuthConfig struct {
	ClientID     string
	ClientSecret string
	Scope        string
	RedirectURL  string
	State        string
	APIBaseURL   string
	OAuth        *oauth2.Config
}

func LoadSpotifyConfigs

func LoadSpotifyConfigs() (*AuthConfig, error)

func LoadTwitchConfigs

func LoadTwitchConfigs() (*AuthConfig, error)

LoadTwitchConfigs reads from environment variables in order to populate configurations for creating a Twitch SDK client

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL