oauth

package
v0.0.0-...-36ecd39 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrOAuthAccountMissingUserID = errors.New("oauth account missing user id")
View Source
var ErrOAuthCallbackInvalid = errors.New("oauth callback invalid")
View Source
var ErrOAuthCodeMissing = errors.New("oauth code missing")
View Source
var ErrOAuthEmailAlreadyRegistered = errors.New("oauth email already registered")
View Source
var ErrOAuthEmailMissing = errors.New("oauth email missing")
View Source
var ErrOAuthIDTokenInvalid = errors.New("oauth id_token invalid")
View Source
var ErrOAuthIDTokenMissing = errors.New("oauth id_token missing")
View Source
var ErrOAuthProvider = errors.New("oauth provider error")
View Source
var ErrOAuthProviderNotFound = errors.New("oauth provider not found")
View Source
var ErrOAuthStateInvalid = errors.New("oauth state invalid")
View Source
var ErrOAuthStateMismatch = errors.New("oauth state mismatch")
View Source
var ErrOAuthStateMissing = errors.New("oauth state missing")
View Source
var ErrOAuthTokenExchange = errors.New("oauth token exchange failed")
View Source
var ErrOAuthUserInfo = errors.New("oauth userinfo fetch failed")

Functions

func ClearOAuthStateCookie

func ClearOAuthStateCookie(w http.ResponseWriter)

func GetOrCreateUserFromOAuth

func GetOrCreateUserFromOAuth(ctx context.Context, db *sql.DB, provider, providerUserID, email string, emailVerified bool) (string, error)

func HandleCallback

func HandleCallback(ctx context.Context, db *sql.DB, stateSecret string, provider OAuthProvider, rawStateCookie, callbackState, callbackErr, code string) (string, error)

func HandleCallbackHTTP

func HandleCallbackHTTP(w http.ResponseWriter, r *http.Request, db *sql.DB, stateSecret string, provider OAuthProvider) (string, error)

func NewRandomURLSafe

func NewRandomURLSafe(n int) (string, error)

func PKCEChallenge

func PKCEChallenge(verifier string) string

func ReadOAuthStateCookie

func ReadOAuthStateCookie(r *http.Request) (string, error)

func SetOAuthStateCookie

func SetOAuthStateCookie(w http.ResponseWriter, value string)

func SignOAuthState

func SignOAuthState(secret, state, verifier string) (string, error)

func Start

func Start(stateSecret string, provider OAuthProvider) (signedState, url string, err error)

func StartHTTP

func StartHTTP(w http.ResponseWriter, r *http.Request, stateSecret string, provider OAuthProvider) error

func ValidateOAuthStateSecret

func ValidateOAuthStateSecret(secret string) error

func VerifyOAuthStateCookie

func VerifyOAuthStateCookie(secret, raw string) (state string, verifier string, err error)

Types

type Client

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

func NewClient

func NewClient(cfg ClientConfig) (*Client, error)

func (*Client) HandleCallbackHTTP

func (c *Client) HandleCallbackHTTP(w http.ResponseWriter, r *http.Request, providerName string) (string, error)

func (*Client) ProviderMetadata

func (c *Client) ProviderMetadata() []OAuthProviderMeta

func (*Client) StartHTTP

func (c *Client) StartHTTP(w http.ResponseWriter, r *http.Request, providerName string) error

type ClientConfig

type ClientConfig struct {
	DB          *sql.DB
	StateSecret string
	Providers   map[string]OAuthProvider
}

type DiscordProvider

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

func NewDiscordProvider

func NewDiscordProvider(cfg DiscordProviderConfig) (*DiscordProvider, error)

func (DiscordProvider) AuthURL

func (p DiscordProvider) AuthURL(state, codeChallenge string) (string, error)

func (DiscordProvider) DisplayName

func (p DiscordProvider) DisplayName() string

func (DiscordProvider) ExchangeAndFetchIdentity

func (p DiscordProvider) ExchangeAndFetchIdentity(ctx context.Context, code, codeVerifier string) (*OAuthIdentity, error)

func (DiscordProvider) Name

func (p DiscordProvider) Name() string

type DiscordProviderConfig

type DiscordProviderConfig struct {
	DisplayName  string
	ClientID     string
	ClientSecret string
	RedirectURL  string
	Scopes       []string

	AuthURL    string
	TokenURL   string
	APIBaseURL string
	HTTPClient *http.Client
}

type GitHubProvider

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

func NewGitHubProvider

func NewGitHubProvider(cfg GitHubProviderConfig) (*GitHubProvider, error)

func (GitHubProvider) AuthURL

func (p GitHubProvider) AuthURL(state, codeChallenge string) (string, error)

func (GitHubProvider) DisplayName

func (p GitHubProvider) DisplayName() string

func (GitHubProvider) ExchangeAndFetchIdentity

func (p GitHubProvider) ExchangeAndFetchIdentity(ctx context.Context, code, codeVerifier string) (*OAuthIdentity, error)

func (GitHubProvider) Name

func (p GitHubProvider) Name() string

type GitHubProviderConfig

type GitHubProviderConfig struct {
	DisplayName  string
	ClientID     string
	ClientSecret string
	RedirectURL  string
	Scopes       []string

	AuthURL    string
	TokenURL   string
	APIBaseURL string
	HTTPClient *http.Client
}

type OAuthCallbackValidator

type OAuthCallbackValidator interface {
	ValidateCallback(r *http.Request) error
}

type OAuthIdentity

type OAuthIdentity struct {
	Provider       string
	ProviderUserID string
	Email          string
	EmailVerified  bool
}

type OAuthProvider

type OAuthProvider interface {
	Name() string
	DisplayName() string
	AuthURL(state, codeChallenge string) (string, error)
	ExchangeAndFetchIdentity(ctx context.Context, code, codeVerifier string) (*OAuthIdentity, error)
}

type OAuthProviderMeta

type OAuthProviderMeta struct {
	Name        string
	DisplayName string
	LoginPath   string
}

func OAuthProviderMetadata

func OAuthProviderMetadata(providers map[string]OAuthProvider) []OAuthProviderMeta

type OIDCProvider

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

func NewOIDCProvider

func NewOIDCProvider(ctx context.Context, cfg OIDCProviderConfig) (*OIDCProvider, error)

func (*OIDCProvider) AuthURL

func (p *OIDCProvider) AuthURL(state, codeChallenge string) (string, error)

func (*OIDCProvider) DisplayName

func (p *OIDCProvider) DisplayName() string

func (*OIDCProvider) ExchangeAndFetchIdentity

func (p *OIDCProvider) ExchangeAndFetchIdentity(ctx context.Context, code, codeVerifier string) (*OAuthIdentity, error)

func (*OIDCProvider) Name

func (p *OIDCProvider) Name() string

type OIDCProviderConfig

type OIDCProviderConfig struct {
	Name         string
	DisplayName  string
	IssuerURL    string
	ClientID     string
	ClientSecret string
	RedirectURL  string
	Scopes       []string
}

type RedditProvider

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

func NewRedditProvider

func NewRedditProvider(cfg RedditProviderConfig) (*RedditProvider, error)

func (RedditProvider) AuthURL

func (p RedditProvider) AuthURL(state, codeChallenge string) (string, error)

func (RedditProvider) DisplayName

func (p RedditProvider) DisplayName() string

func (RedditProvider) ExchangeAndFetchIdentity

func (p RedditProvider) ExchangeAndFetchIdentity(ctx context.Context, code, codeVerifier string) (*OAuthIdentity, error)

func (RedditProvider) Name

func (p RedditProvider) Name() string

type RedditProviderConfig

type RedditProviderConfig struct {
	DisplayName  string
	ClientID     string
	ClientSecret string
	RedirectURL  string
	Scopes       []string

	PseudoEmailDomain string
	UserAgent         string

	AuthURL    string
	TokenURL   string
	APIBaseURL string
	HTTPClient *http.Client
}

type ShopifyProvider

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

func NewShopifyProvider

func NewShopifyProvider(cfg ShopifyProviderConfig) (*ShopifyProvider, error)

func (ShopifyProvider) AuthURL

func (p ShopifyProvider) AuthURL(state, codeChallenge string) (string, error)

func (ShopifyProvider) DisplayName

func (p ShopifyProvider) DisplayName() string

func (ShopifyProvider) ExchangeAndFetchIdentity

func (p ShopifyProvider) ExchangeAndFetchIdentity(ctx context.Context, code, codeVerifier string) (*OAuthIdentity, error)

func (ShopifyProvider) Name

func (p ShopifyProvider) Name() string

func (*ShopifyProvider) ValidateCallback

func (p *ShopifyProvider) ValidateCallback(r *http.Request) error

type ShopifyProviderConfig

type ShopifyProviderConfig struct {
	DisplayName  string
	ClientID     string
	ClientSecret string
	RedirectURL  string
	Scopes       []string
	ShopDomain   string

	AuthURL    string
	TokenURL   string
	APIBaseURL string
	HTTPClient *http.Client
}

type SpotifyProvider

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

func NewSpotifyProvider

func NewSpotifyProvider(cfg SpotifyProviderConfig) (*SpotifyProvider, error)

func (SpotifyProvider) AuthURL

func (p SpotifyProvider) AuthURL(state, codeChallenge string) (string, error)

func (SpotifyProvider) DisplayName

func (p SpotifyProvider) DisplayName() string

func (SpotifyProvider) ExchangeAndFetchIdentity

func (p SpotifyProvider) ExchangeAndFetchIdentity(ctx context.Context, code, codeVerifier string) (*OAuthIdentity, error)

func (SpotifyProvider) Name

func (p SpotifyProvider) Name() string

type SpotifyProviderConfig

type SpotifyProviderConfig struct {
	DisplayName  string
	ClientID     string
	ClientSecret string
	RedirectURL  string
	Scopes       []string

	PseudoEmailDomain string

	AuthURL    string
	TokenURL   string
	APIBaseURL string
	HTTPClient *http.Client
}

type TwitterProvider

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

func NewTwitterProvider

func NewTwitterProvider(cfg TwitterProviderConfig) (*TwitterProvider, error)

func (TwitterProvider) AuthURL

func (p TwitterProvider) AuthURL(state, codeChallenge string) (string, error)

func (TwitterProvider) DisplayName

func (p TwitterProvider) DisplayName() string

func (TwitterProvider) ExchangeAndFetchIdentity

func (p TwitterProvider) ExchangeAndFetchIdentity(ctx context.Context, code, codeVerifier string) (*OAuthIdentity, error)

func (TwitterProvider) Name

func (p TwitterProvider) Name() string

type TwitterProviderConfig

type TwitterProviderConfig struct {
	DisplayName  string
	ClientID     string
	ClientSecret string
	RedirectURL  string
	Scopes       []string

	PseudoEmailDomain string

	AuthURL    string
	TokenURL   string
	APIBaseURL string
	HTTPClient *http.Client
}

Jump to

Keyboard shortcuts

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