Documentation
¶
Overview ¶
Package social provides Better Auth-compatible built-in OAuth2/OIDC provider presets and a generic provider constructor.
Index ¶
- Variables
- type AccountSubject
- type EndpointValidator
- type Options
- type ProfileMapper
- type Provider
- func (p *Provider) AuthorizationURL(state, challenge, nonce, redirectURI string) (string, error)
- func (p *Provider) DisableImplicitSignUp() bool
- func (p *Provider) DisableSignUp() bool
- func (p *Provider) EndSessionURL(request betterauth.OAuthEndSessionRequest) (string, error)
- func (p *Provider) Exchange(ctx context.Context, code string, verifier string, nonce string, ...) (betterauth.OAuthResult, error)
- func (p *Provider) Refresh(ctx context.Context, refreshToken string) (betterauth.ProviderTokens, error)
- type TokenAuthMethod
- type TokenRequest
- type TokenRequestHook
Constants ¶
This section is empty.
Variables ¶
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
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 ¶
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 NewOIDC ¶
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 (*Provider) DisableImplicitSignUp ¶
DisableImplicitSignUp implements betterauth.OAuthProviderSignUpPolicy.
func (*Provider) DisableSignUp ¶
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.