providers

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DiscordKeyModeID uses the user's Discord ID as their unique identifier.
	DiscordKeyModeID discordKeyMode = iota
	// DiscordKeyModeEmail uses the user's email address as their unique identifier.
	DiscordKeyModeEmail
)
View Source
const (
	// TwitchKeyModeID uses the user's Twitch ID as their unique identifier.
	TwitchKeyModeID twitchKeyMode = iota
	// TwitchKeyModeEmail uses the user's email address as their unique identifier.
	TwitchKeyModeEmail
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Discord

type Discord struct {
	Provider
	// contains filtered or unexported fields
}

Discord provides OAuth2 authentication using Discord's OAuth2 service. It implements the basic OAuth2 flow for Discord authentication with configurable key modes.

func NewDiscord

func NewDiscord(sesh Gosesher, clientID, clientSecret, redirectPath string, opts ...Opt[Discord]) *Discord

NewDiscord creates a new Discord OAuth2 provider with the given configuration. The redirectPath parameter should have a leading slash. Additional options can be provided to customize the provider's behavior.

func (*Discord) NewUser added in v0.1.1

func (d *Discord) NewUser() *DiscordUser

NewUser creates a new DiscordUser instance with the current key mode.

func (*Discord) OAuth2Begin

func (d *Discord) OAuth2Begin() http.HandlerFunc

OAuth2Begin returns a handler that initiates the Discord OAuth2 flow.

func (*Discord) OAuth2Callback

func (d *Discord) OAuth2Callback(handler gosesh.HandlerDoneFunc) http.HandlerFunc

OAuth2Callback returns a handler that completes the Discord OAuth2 flow. The handler parameter is called when the flow completes, with any error that occurred.

type DiscordUser

type DiscordUser struct {
	ID       string `json:"id"`                 // The user's unique Discord ID
	Username string `json:"username"`           // The user's Discord username
	Email    string `json:"email,omitempty"`    // The user's email address (requires email scope)
	Verified bool   `json:"verified,omitempty"` // Whether the email is verified
	// contains filtered or unexported fields
}

DiscordUser represents a user authenticated through Discord's OAuth2 service. It contains the user's Discord account information.

func (DiscordUser) String

func (user DiscordUser) String() string

String returns either the user's ID or email as their unique identifier, depending on the configured key mode.

type Google added in v0.5.0

type Google struct {
	Provider
}

Google provides OAuth2 authentication using Google's OAuth2 service. It implements the basic OAuth2 flow for Google authentication.

func NewGoogle

func NewGoogle(sesh Gosesher, clientID, clientSecret, redirectPath string) *Google

NewGoogle creates a new Google OAuth2 provider with the given configuration. The redirectPath parameter should have a leading slash.

func (*Google) NewUser added in v0.5.2

func (p *Google) NewUser() *GoogleUser

NewUser creates a new GoogleUser instance.

func (*Google) OAuth2Begin added in v0.5.0

func (p *Google) OAuth2Begin() http.HandlerFunc

OAuth2Begin returns a handler that initiates the Google OAuth2 flow.

func (*Google) OAuth2Callback added in v0.5.0

func (p *Google) OAuth2Callback(handler gosesh.HandlerDoneFunc) http.HandlerFunc

OAuth2Callback returns a handler that completes the Google OAuth2 flow. The handler parameter is called when the flow completes, with any error that occurred.

type GoogleTokenInfoValidator added in v0.10.0

type GoogleTokenInfoValidator struct {
	// contains filtered or unexported fields
}

GoogleTokenInfoValidator validates Google OAuth tokens using the tokeninfo endpoint.

func NewGoogleTokenInfoValidator added in v0.10.0

func NewGoogleTokenInfoValidator(client *http.Client) *GoogleTokenInfoValidator

NewGoogleTokenInfoValidator creates a validator for Google access tokens. If client is nil, http.DefaultClient will be used.

func (*GoogleTokenInfoValidator) ValidateAudience added in v0.10.0

func (v *GoogleTokenInfoValidator) ValidateAudience(ctx context.Context, accessToken string) (string, error)

ValidateAudience calls Google's tokeninfo endpoint to get the token's audience.

type GoogleUser added in v0.5.1

type GoogleUser struct {
	ID            string `json:"id"`             // The user's unique Google ID
	Email         string `json:"email"`          // The user's email address
	VerifiedEmail bool   `json:"verified_email"` // Whether the email is verified
	Picture       string `json:"picture"`        // URL to the user's profile picture
}

GoogleUser represents a user authenticated through Google's OAuth2 service. It contains the user's Google account information.

func (*GoogleUser) String added in v0.5.1

func (user *GoogleUser) String() string

String returns the user's email address as their unique identifier.

type Gosesher

type Gosesher interface {
	OAuth2Begin(cfg *oauth2.Config) http.HandlerFunc
	OAuth2Callback(
		config *oauth2.Config, request gosesh.RequestFunc, unmarshal gosesh.UnmarshalFunc, done gosesh.HandlerDoneFunc,
	) http.HandlerFunc
	Scheme() string
	Host() string
}

Gosesher is an interface that defines the required methods for OAuth2 authentication. It is implemented by the gosesh.Gosesh type and used by providers to handle the OAuth2 flow.

type Opt added in v0.7.0

type Opt[T any] func(*T)

Opt is a function type for configuring provider options.

func WithDiscordEmailScope added in v0.7.0

func WithDiscordEmailScope() Opt[Discord]

WithDiscordEmailScope adds the email scope to the Discord provider's OAuth2 configuration. This is required to access the user's email address.

func WithDiscordKeyMode added in v0.1.0

func WithDiscordKeyMode(mode discordKeyMode) Opt[Discord]

WithDiscordKeyMode sets the key mode for the Discord provider. The key mode determines whether to use the user's ID or email as their unique identifier.

func WithEmailScope added in v0.7.0

func WithEmailScope() Opt[Twitch]

WithEmailScope adds the email scope to the Twitch provider's OAuth2 configuration. This is required to access the user's email address.

func WithTwitchKeyMode added in v0.7.0

func WithTwitchKeyMode(mode twitchKeyMode) Opt[Twitch]

WithTwitchKeyMode sets the key mode for the Twitch provider. The key mode determines whether to use the user's ID or email as their unique identifier.

type Provider added in v0.5.0

type Provider struct {
	Gosesh Gosesher
	Config *oauth2.Config
	// contains filtered or unexported fields
}

Provider is the base type for all OAuth2 providers. It contains common functionality shared by all providers.

type Twitch added in v0.7.0

type Twitch struct {
	Provider
	// contains filtered or unexported fields
}

Twitch provides OAuth2 authentication using Twitch's OAuth2 service. It implements the basic OAuth2 flow for Twitch authentication with configurable key modes.

func NewTwitch added in v0.7.0

func NewTwitch(sesh Gosesher, clientID, clientSecret, redirectPath string, opts ...Opt[Twitch]) *Twitch

NewTwitch creates a new Twitch OAuth2 provider with the given configuration. The redirectPath parameter should have a leading slash. Additional options can be provided to customize the provider's behavior.

func (*Twitch) NewUser added in v0.7.0

func (t *Twitch) NewUser() *TwitchUser

NewUser creates a new TwitchUser instance with the current key mode.

func (*Twitch) OAuth2Begin added in v0.7.0

func (t *Twitch) OAuth2Begin() http.HandlerFunc

OAuth2Begin returns a handler that initiates the Twitch OAuth2 flow.

func (*Twitch) OAuth2Callback added in v0.7.0

func (t *Twitch) OAuth2Callback(handler gosesh.HandlerDoneFunc) http.HandlerFunc

OAuth2Callback returns a handler that completes the Twitch OAuth2 flow. The handler parameter is called when the flow completes, with any error that occurred.

type TwitchUser added in v0.7.0

type TwitchUser struct {
	Data []struct {
		ID    string `json:"id"`    // The user's unique Twitch ID
		Login string `json:"login"` // The user's Twitch login name
		Email string `json:"email"` // The user's email address (requires email scope)
	} `json:"data"`
	// contains filtered or unexported fields
}

TwitchUser represents a user authenticated through Twitch's OAuth2 service. It contains the user's Twitch account information.

func (*TwitchUser) String added in v0.7.0

func (user *TwitchUser) String() string

String returns either the user's ID or email as their unique identifier, depending on the configured key mode.

Jump to

Keyboard shortcuts

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