social

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 19 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package social provides Better Auth-compatible built-in OAuth2/OIDC provider presets and a generic provider constructor.

Index

Constants

This section is empty.

Variables

View Source
var SupportedProviders = []string{
	"apple", "atlassian", "cloudflare", "cognito", "discord", "dropbox", "facebook",
	"figma", "github", "gitlab", "google", "huggingface", "kakao", "kick", "line",
	"linear", "linkedin", "microsoft", "naver", "notion", "paybin", "paypal",
	"polar", "railway", "reddit", "roblox", "salesforce", "slack", "spotify",
	"tiktok", "twitch", "twitter", "vercel", "vk", "wechat", "zoom",
}

SupportedProviders is the Better Auth v1.7 built-in provider catalog.

Functions

This section is empty.

Types

type AccountSubject added in v1.1.0

type AccountSubject func(map[string]any) (string, error)

AccountSubject resolves the immutable provider-side identifier from the raw provider profile. It is required for custom non-OIDC providers; mutable local-user mappings must never choose account identity.

type EndpointValidator

type EndpointValidator func(context.Context, *url.URL) error

EndpointValidator is called for OIDC discovery and every discovered endpoint before a provider is constructed. It lets embedders apply an SSRF policy that is stricter than the generic public-address checks.

type Options

type Options struct {
	ClientID              string
	ClientSecret          string
	ClientKey             string
	Issuer                string
	BaseURL               string
	Tenant                string
	Scopes                []string
	DisableDefaultScope   bool
	AuthorizationURL      string
	TokenURL              string
	UserInfoURL           string
	JWKSURL               string
	TokenAuth             TokenAuthMethod
	ProfileMapper         ProfileMapper
	AccountSubject        AccountSubject
	AuthorizationParams   map[string]string
	RefreshTokenParams    map[string]string
	EndSessionURL         string
	DisableProviderLogout bool
	PostLogoutRedirectURI string
	HTTPClient            *http.Client
	Timeout               time.Duration
	MaxResponseBytes      int64
	// Clock controls token-expiry and OIDC verification time in deterministic
	// tests. Nil uses the system UTC clock.
	Clock betterauth.Clock
	// DiscoveryURL overrides the standard issuer well-known location.
	DiscoveryURL string
	// ValidateEndpoint validates discovery, authorization, token, user-info,
	// and JWKS URLs before any runtime request can use them.
	ValidateEndpoint EndpointValidator
	// DisableImplicitSignUp requires callers to set requestSignUp for a new
	// account while still allowing returning users to sign in.
	DisableImplicitSignUp bool
	// DisableSignUp permanently prevents this provider from creating users.
	DisableSignUp bool
	// CustomizeTokenRequest adds provider-specific client authentication to
	// token requests. It is required when TokenAuth is TokenAuthCustom and is
	// rejected otherwise.
	CustomizeTokenRequest TokenRequestHook
	// contains filtered or unexported fields
}

Options configures a built-in preset. Endpoint overrides are intended for self-hosted GitLab, Cognito, Microsoft tenants, Salesforce, and compatible private OAuth deployments.

type ProfileMapper

type ProfileMapper func(map[string]any) (betterauth.OAuthProfile, error)

type Provider

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

Provider is immutable after construction and safe for concurrent use.

func New

func New(providerID string, options Options) (*Provider, error)

func NewOIDC

func NewOIDC(ctx context.Context, providerID string, options Options) (*Provider, error)

NewOIDC discovers and validates a generic OpenID Connect provider before constructing an immutable OAuth provider. Issuer is required; explicit endpoint options override discovered values only after the discovered configuration itself has passed validation.

func (*Provider) AuthorizationURL

func (p *Provider) AuthorizationURL(state, challenge, nonce, redirectURI string) (string, error)

func (*Provider) DisableImplicitSignUp

func (p *Provider) DisableImplicitSignUp() bool

DisableImplicitSignUp implements betterauth.OAuthProviderSignUpPolicy.

func (*Provider) DisableSignUp

func (p *Provider) DisableSignUp() bool

DisableSignUp implements betterauth.OAuthProviderSignUpPolicy.

func (*Provider) EndSessionURL added in v1.1.0

func (p *Provider) EndSessionURL(request betterauth.OAuthEndSessionRequest) (string, error)

EndSessionURL builds a validated OIDC RP-initiated logout URL.

func (*Provider) Exchange

func (p *Provider) Exchange(
	ctx context.Context,
	code string,
	verifier string,
	nonce string,
	redirectURI string,
) (betterauth.OAuthResult, error)

func (*Provider) Refresh

func (p *Provider) Refresh(ctx context.Context, refreshToken string) (betterauth.ProviderTokens, error)

Refresh exchanges a refresh token using the provider's configured token endpoint and client authentication method.

type TokenAuthMethod

type TokenAuthMethod string
const (
	TokenAuthBody  TokenAuthMethod = "client_secret_post"
	TokenAuthBasic TokenAuthMethod = "client_secret_basic"
	TokenAuthNone  TokenAuthMethod = "none"
	// TokenAuthCustom lets Options.CustomizeTokenRequest add the client
	// authentication a provider needs. Nothing else is added for it.
	TokenAuthCustom TokenAuthMethod = "custom"
)

type TokenRequest added in v1.1.0

type TokenRequest struct {
	// Body holds the form parameters sent to the token endpoint.
	Body url.Values
	// Header holds the request headers.
	Header        http.Header
	ClientID      string
	ClientSecret  string
	TokenEndpoint string
	// GrantType is "authorization_code" or "refresh_token".
	GrantType string
}

TokenRequest is a token endpoint request that a custom authentication hook may change. The standard grant parameters are already set in Body.

type TokenRequestHook added in v1.1.0

type TokenRequestHook func(context.Context, *TokenRequest) error

TokenRequestHook adds provider-specific client authentication to a token request. It is the Go form of Better Auth's `custom` token endpoint authentication and is used only when TokenAuth is TokenAuthCustom.

Jump to

Keyboard shortcuts

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