package discord import ( "fmt" "net/url" "github.com/pkg/errors" ) type Token struct { AccessToken string TokenType string ExpiresIn int RefreshToken string Scope string } const oauthurl string = "https://discord.com/oauth2/authorize" func GetOAuthLink(cfg *Config, state string, trustedHost string) (string, error) { if cfg == nil { return "", errors.New("cfg cannot be nil") } if state == "" { return "", errors.New("state cannot be empty") } if trustedHost == "" { return "", errors.New("trustedHost cannot be empty") } values := url.Values{} values.Add("response_type", "code") values.Add("client_id", cfg.ClientID) values.Add("scope", cfg.OAuthScopes) values.Add("state", state) values.Add("redirect_uri", fmt.Sprintf("%s/%s", trustedHost, cfg.RedirectPath)) values.Add("prompt", "none") return fmt.Sprintf("%s?%s", oauthurl, values.Encode()), nil }