Documentation ¶
Index ¶
- Constants
- Variables
- func GetUserData(token string) map[string]interface{}
- type DiscordClient
- func (dc *DiscordClient) AppendScopes()
- func (dc *DiscordClient) CheckStructErrors()
- func (dc *DiscordClient) GetAccessToken(code string) string
- func (dc *DiscordClient) GetAccessTokenBody(code string) *bytes.Buffer
- func (dc *DiscordClient) InitOAuthURL()
- func (dc *DiscordClient) RedirectHandler(w http.ResponseWriter, r *http.Request, state string)
Constants ¶
const ( // Non-Whitelist ScopeIdentify = "identify" ScopeBot = "bot" ScopeEmail = "email" ScopeGuilds = "guilds" ScopeGuildsJoin = "guilds.join" ScopeConnections = "connections" ScopeGroupDMJoin = "gdm.join" ScopeMessagesRead = "messages.read" ScopeWebhookIncoming = "webhook.Incoming" ScopeApplicationsBuildsRead = "applications.builds.read" ScopeApplicationsStoreUpdate = "applications.store.update" ScopeApplicationsEntitlements = "applications.entitlements" ScopeApplicationsCommands = "applications.commands" ScopeApplicationsCommandsUpdate = "applications.commands.update" // Whitelist Only ScopeRPC = "rpc" ScopeRPCAPI = "rpc.api" ScopeRPCNotificationsRead = "rpc.notifications.read" ScopeApplicationsBuildsUpload = "applications.builds.upload" ScopeRelationshipsRead = "relationships.read" ScopeActivitiesRead = "activities.read" ScopeActivitiesWrite = "activities.write" )
Constant OAuth URL Scopes
Variables ¶
var RequestClient *http.Client = &http.Client{}
Request Client for sending http requests
Functions ¶
func GetUserData ¶
The GetUserData() function is used to send an api request to the discord/users/@me endpoint with the provided accessToken.
Types ¶
type DiscordClient ¶
type DiscordClient struct { ClientID string ClientSecret string RedirectURI string Scopes []string OAuthURL string }
The DiscordClient struct contains five primary keys
ClientID: string { "Your Application's Client ID" } ClientSecret: string { "Your Application's Client Secret" } Scopes: []string { "Your Application's Permission Scopes (REQUIRED)" } RedirectURI: string { "The Redirect URI (This is where you use the GetUserData functions)" } OAuthURL: string { "Your Application's OAuth URL (If none is provided, one will be generated for you)" }
func Init ¶
func Init(dc *DiscordClient) *DiscordClient
The Init() function is used to initalize the required data for the discord oauth to work It panics if required parameters are missing from the provided DiscordClient struct
func (*DiscordClient) AppendScopes ¶
func (dc *DiscordClient) AppendScopes()
The AppendScopes() function is used to append the provided scopes to the OAuth URL. This function is called from the InitOAuthURL() function and is only ran if the number of provided scopes is valid.
func (*DiscordClient) CheckStructErrors ¶
func (dc *DiscordClient) CheckStructErrors()
The CheckStructErrors() function is used to check for any invalid / empty struct values that are required for the discord oauth to work.
func (*DiscordClient) GetAccessToken ¶
func (dc *DiscordClient) GetAccessToken(code string) string
The GetAccessToken() function is used to send an api request to discord's oauth2/token endpoint. The function returns the token required for accessing the authorized users data
func (*DiscordClient) GetAccessTokenBody ¶
func (dc *DiscordClient) GetAccessTokenBody(code string) *bytes.Buffer
The GetAccessTokenBody() function is used to return the request body bytes being used in the GetAccessToken() http request
func (*DiscordClient) InitOAuthURL ¶
func (dc *DiscordClient) InitOAuthURL()
The InitOAuthURL() function is used to initialize a discord OAuth URL. This function is called from the Init() function and is only ran if there is no previously provided OAuth URL.
func (*DiscordClient) RedirectHandler ¶
func (dc *DiscordClient) RedirectHandler(w http.ResponseWriter, r *http.Request, state string)
The RedirectHandler() function is used to redirect the user to the provided DiscordClient OAuth URL. If there is a provided state, it will add it to said OAuth URL
If using a state, base64encode the data beforehand, else, set the state to "" (length: 0)