oauth

package
v0.0.0-...-84602f5 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const StateLength = 32

StateLength is the integer number of characters that every state string will container

View Source
const UserEndpoint = "https://discord.com/api/oauth2/@me"

UserEndpoint is the endpoint to request when fetching Discord user data

Variables

View Source
var Config = &oauth2.Config{
	ClientID:     config.Web.OAuth.ClientID,
	ClientSecret: config.Web.OAuth.ClientSecret,
	Endpoint: oauth2.Endpoint{
		AuthURL:   "https://discord.com/api/oauth2/authorize",
		TokenURL:  "https://discord.com/api/oauth2/token",
		AuthStyle: oauth2.AuthStyleInParams,
	},
	RedirectURL: config.Web.Domain().String() + "/auth/callback",
	Scopes:      []string{"identify"},
}

Functions

func NewState

func NewState() string

NewState generates a new random state and adds it to the list of valid states This uses a mutex to prevent two goroutines trying to add a new state at the same time

func PopState

func PopState(state string) bool

PopState checks to see if a given state is valid. If it is, it's removed from the list of valid states This uses a mutex lock to prevent concurrent goroutines from trying to pop a state at the same time

Types

type User

type User struct {
	AvatarHash  string `json:"avatar"`
	DisplayName string `json:"global_name"`
	ID          string `json:"id"`
	Username    string `json:"username"`
}

User holds information about a Discord user

func GetUser

func GetUser(token *oauth2.Token) (*User, error)

GetUser takes an OAuth bearer token and fetches data for the user it belongs to

func (*User) AvatarURL

func (u *User) AvatarURL(size uint16) string

type UserEndpointPayload

type UserEndpointPayload struct {
	User User `json:"user"`
}

UserEndpointPayload wraps the JSON response from Discord when requesting UserEndpoint

Jump to

Keyboard shortcuts

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