Skip to content

Commit

Permalink
cleaned up
Browse files Browse the repository at this point in the history
  • Loading branch information
realTristan committed Dec 12, 2022
1 parent 24e5736 commit fcf8ed9
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
// Main function
func main() {
// Establish a new discord client
var dc *disgoauth.DiscordClient = discord.Init(&disgoauth.Client{
var dc *disgoauth.Client = disgoauth.Init(&disgoauth.Client{
ClientID: "CLIENT ID",
ClientSecret: "CLIENT SECRET",
RedirectURI: "http://localhost:8000/redirect",
Expand Down
22 changes: 11 additions & 11 deletions access_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// The accessTokenBody() function is used to return
// the request body bytes being used in the
// GetAccessToken() function
func (dc *DiscordClient) accessTokenBody(code string) *bytes.Buffer {
func (dc *Client) accessTokenBody(code string) *bytes.Buffer {
return bytes.NewBuffer([]byte(fmt.Sprintf(
"client_id=%s&client_secret=%s&grant_type=authorization_code&redirect_uri=%s&code=%s&scope=identify",
dc.ClientID, dc.ClientSecret, dc.RedirectURI, code,
Expand All @@ -23,7 +23,7 @@ func (dc *DiscordClient) accessTokenBody(code string) *bytes.Buffer {
// The refreshAccessTokenBody() function is used to return
// the request body bytes being used in the
// RefreshAccessToken() function
func (dc *DiscordClient) refreshAccessTokenBody(refreshToken string) *bytes.Buffer {
func (dc *Client) refreshAccessTokenBody(refreshToken string) *bytes.Buffer {
return bytes.NewBuffer([]byte(fmt.Sprintf(
"client_id=%s&client_secret=%s&grant_type=refresh_token&redirect_uri=%s&refresh_token=%s",
dc.ClientID, dc.ClientSecret, dc.RefreshRedirectURI, refreshToken,
Expand Down Expand Up @@ -64,7 +64,7 @@ func credentialsAccessTokenBody(scopes []string) *bytes.Buffer {
// The accessTokenRequestObject() function is used to establish
// a new request object that will be used for sending
// the api request to the discord oauth token endpoint.
func (dc *DiscordClient) accessTokenRequestObject(body *bytes.Buffer, creds bool) (*http.Request, error) {
func (dc *Client) accessTokenRequestObject(body *bytes.Buffer, creds bool) (*http.Request, error) {
// Establish a new request object
var req, err = http.NewRequest("POST",
"https://discordapp.com/api/oauth2/token", body,
Expand Down Expand Up @@ -94,7 +94,7 @@ func (dc *DiscordClient) accessTokenRequestObject(body *bytes.Buffer, creds bool
// request to discord's oauth2/token endpoint.
// The function returns the data required for
// accessing the authorized users data
func (dc *DiscordClient) accessTokenRequest(req *http.Request) (map[string]interface{}, error) {
func (dc *Client) accessTokenRequest(req *http.Request) (map[string]interface{}, error) {
// Send the http request
resp, err := RequestClient.Do(req)

Expand Down Expand Up @@ -132,7 +132,7 @@ func (dc *DiscordClient) accessTokenRequest(req *http.Request) (map[string]inter
// The GetAccessToken() function is used to get the users
// bearer access token, refresh token, the token expiry
// and any errors that occured.
func (dc *DiscordClient) GetAccessToken(code string) (string, string, int, error) {
func (dc *Client) GetAccessToken(code string) (string, string, int, error) {
// Define Variables
var (
// The Access Token Request Body
Expand Down Expand Up @@ -164,7 +164,7 @@ func (dc *DiscordClient) GetAccessToken(code string) (string, string, int, error

// The GetOnlyAccessToken() function is used to get
// the users bearer access token.
func (dc *DiscordClient) GetOnlyAccessToken(code string) (string, error) {
func (dc *Client) GetOnlyAccessToken(code string) (string, error) {
// Define Variables
var (
// The Access Token Request Body
Expand Down Expand Up @@ -196,7 +196,7 @@ func (dc *DiscordClient) GetOnlyAccessToken(code string) (string, error) {

// The GetAccessTokenMap() function is used to return all
// the map data revolving around the access token
func (dc *DiscordClient) GetAccessTokenMap(code string) (map[string]interface{}, error) {
func (dc *Client) GetAccessTokenMap(code string) (map[string]interface{}, error) {
// Define Variables
var (
// The Access Token Request Body
Expand All @@ -217,7 +217,7 @@ func (dc *DiscordClient) GetAccessTokenMap(code string) (map[string]interface{},

// The RefreshAccessToken() function is used to refresh
// the users bearer authorization token.
func (dc *DiscordClient) RefreshAccessToken(refreshToken string) (map[string]interface{}, error) {
func (dc *Client) RefreshAccessToken(refreshToken string) (map[string]interface{}, error) {
// Define Variables
var (
// The Access Token Request Body
Expand All @@ -239,7 +239,7 @@ func (dc *DiscordClient) RefreshAccessToken(refreshToken string) (map[string]int
// The GetCredentialsAccessToken() function is used to get
// the credentials auth token, refresh token, the token expiry
// timing, and any errors that had occured.
func (dc *DiscordClient) GetCredentialsAccessToken(scopes []string) (string, string, int, error) {
func (dc *Client) GetCredentialsAccessToken(scopes []string) (string, string, int, error) {
// Define Variables
var (
// The Access Token Request Body
Expand Down Expand Up @@ -271,7 +271,7 @@ func (dc *DiscordClient) GetCredentialsAccessToken(scopes []string) (string, str

// The GetOnlyCredentialsAccessToken() function is used to get
// the users credentials access bearer auth token.
func (dc *DiscordClient) GetOnlyCredentialsAccessToken(scopes []string) (string, error) {
func (dc *Client) GetOnlyCredentialsAccessToken(scopes []string) (string, error) {
// Define Variables
var (
// The Access Token Request Body
Expand Down Expand Up @@ -305,7 +305,7 @@ func (dc *DiscordClient) GetOnlyCredentialsAccessToken(scopes []string) (string,
// The GetCredentialsAccessTokenMap() function
// is used to return all the map data revolving
// around the credentials access token
func (dc *DiscordClient) GetCredentialsAccessTokenMap(scopes []string) (map[string]interface{}, error) {
func (dc *Client) GetCredentialsAccessTokenMap(scopes []string) (map[string]interface{}, error) {
// Define Variables
var (
// The Access Token Request Body
Expand Down
16 changes: 8 additions & 8 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
// Request Client for sending http requests
var RequestClient *http.Client = &http.Client{}

// The DiscordClient struct contains five primary keys
// The Client struct contains five primary keys
/* ClientID: string { "Your Application's Client ID (REQUIRED)" } */
/* ClientSecret: string { "Your Application's Client Secret (REQUIRED)" } */
/* Scopes: []string { "Your Application's Permission Scopes (REQUIRED)" } */
Expand All @@ -35,22 +35,22 @@ func (dc *Client) checkStructErrors() {
// Make sure the user has provided
// a valid client id
if len(dc.ClientID) < 1 {
panic("DisGOAuth Error: invalid ClientID in DiscordClient (ClientID: string)")
panic("DisGOAuth Error: invalid ClientID in Client (ClientID: string)")
}
// Make sure the user has provided
// a valid client secret
if len(dc.ClientSecret) < 1 {
panic("DisGOAuth Error: invalid ClientSecret in DiscordClient (ClientSecret: string)")
panic("DisGOAuth Error: invalid ClientSecret in Client (ClientSecret: string)")
}
// Make sure the user has provided
// a valid redirect uri
if len(dc.RedirectURI) < 1 {
panic("DisGOAuth Error: invalid RedirectURI in DiscordClient (RedirectURI: string)")
panic("DisGOAuth Error: invalid RedirectURI in Client (RedirectURI: string)")
}
// Make sure the user has provided
// a sufficient number of scopes
if len(dc.Scopes) < 1 {
panic("DisGOAuth Error: not enough scopes in DiscordClient (Scopes: []string)")
panic("DisGOAuth Error: not enough scopes in Client (Scopes: []string)")
}
}

Expand Down Expand Up @@ -103,9 +103,9 @@ func (dc *Client) initOAuthURL() string {
// 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 Init(dc *Client) *DiscordClient {
// Check for DiscordClient struct errors
// the provided Client struct
func Init(dc *Client) *Client {
// Check for Client struct errors
dc.checkStructErrors() // discord_client.go (this file)

// Initialize the OAuth URL
Expand Down
8 changes: 4 additions & 4 deletions examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import (
"net/http"

// Import DisGOAuth
discord "github.com/realTristan/disgoauth"
disgoauth "github.com/realTristan/disgoauth"
)

// Main function
func main() {
// Establish a new discord client
var dc *discord.DiscordClient = discord.Init(&discord.DiscordClient{
var dc *disgoauth.Client = disgoauth.Init(&disgoauth.Client{
ClientID: "883006609280864257",
ClientSecret: "X-9n0rEBywVu1KKKOQSHskRQM7L8UlOV",
RedirectURI: "http://localhost:8000/redirect",
Scopes: []string{discord.ScopeIdentify},
Scopes: []string{disgoauth.ScopeIdentify},
})

////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -55,7 +55,7 @@ func main() {
accessToken, _ = dc.GetOnlyAccessToken(codeFromURLParamaters)

// Get the authorized user's data using the above accessToken
userData, _ = discord.GetUserData(accessToken)
userData, _ = disgoauth.GetUserData(accessToken)
)
// Print the user data map
fmt.Fprint(w, userData)
Expand Down
4 changes: 2 additions & 2 deletions implicit.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "fmt"
// The implicitOAuth() function uses the implicit
// and less-safe response type for getting the
// users access token
func (dc *DiscordClient) implicitOAuth() string {
func (dc *Client) implicitOAuth() string {
// Return the OAuth URL to a formatted string
// that contains the client id, redirect uri,
// and response type.
Expand All @@ -19,7 +19,7 @@ func (dc *DiscordClient) implicitOAuth() string {

// The nonImplicitOAuth() function uses the default and
// safer response type for getting the users access token
func (dc *DiscordClient) nonImplicitOAuth() string {
func (dc *Client) nonImplicitOAuth() string {
// Establish the prompt parameter
var prompt string = dc.Prompt
if len(dc.Prompt) > 0 {
Expand Down
4 changes: 2 additions & 2 deletions redirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ package disgoauth
import "net/http"

// The RedirectHandler() function is used to redirect the user
// to the provided DiscordClient OAuth URL. If there is a
// to the provided Client 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)
func (dc *DiscordClient) RedirectHandler(w http.ResponseWriter, r *http.Request, state string) {
func (dc *Client) RedirectHandler(w http.ResponseWriter, r *http.Request, state string) {
// Create a copy of the OAuth URL
var _url string = dc.OAuthURL

Expand Down

0 comments on commit fcf8ed9

Please sign in to comment.