Documentation ¶
Overview ¶
package discordoauth provides fasthttp handlers to authenticate with via the Discord OAuth2 endpoint. v2 swapped support for fasthttp-router to support for fiber handlers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DiscordOAuth ¶
type DiscordOAuth struct {
// contains filtered or unexported fields
}
DiscordOAuth provides http handlers for authenticating a discord User by your Discord OAuth application.
func NewDiscordOAuth ¶
func NewDiscordOAuth(clientID, clientSecret, redirectURI string, onError OnErrorFunc, onSuccess OnSuccessFuc) (*DiscordOAuth, error)
NewDiscordOAuth returns a new instance of DiscordOAuth.
func (*DiscordOAuth) HandlerCallback ¶
func (d *DiscordOAuth) HandlerCallback(ctx *fiber.Ctx) error
HandlerCallback will be requested by discordapp.com on successful app authentication. This handler will check the validity of the passed authorization code by getting a bearer token and trying to get self user data by requesting them using the bearer token. If this fails, onError will be called. Else, onSuccess will be called passing the userID of the user authenticated.
func (*DiscordOAuth) HandlerInit ¶
func (d *DiscordOAuth) HandlerInit(ctx *fiber.Ctx) error
HandlerInit returns a redirect response to the OAuth Apps authentication page.
func (*DiscordOAuth) HandlerInitWithState ¶
func (d *DiscordOAuth) HandlerInitWithState(ctx *fiber.Ctx, state map[string]string) error
HandlerInitWithState returns a redirect response to the OAuth Apps authentication page with a passed state map which is then packed into the result passed to the onSuccess handler.
type OnErrorFunc ¶
OnErrorFunc is the function to be used to handle errors during authentication.
type OnSuccessFuc ¶
type OnSuccessFuc func(ctx *fiber.Ctx, res SuccessResult) error
OnSuccessFuc is the func to be used to handle the successful authentication.