Documentation
¶
Overview ¶
Package supabase integrates Supabase Auth with go-auth's hardened OIDC and provider-session boundaries.
The package intentionally exposes narrow configuration, lifecycle, factor, session, and OAuth authorization-decision services. It does not expose an arbitrary privileged HTTP client, render login/consent UI, own business authorization, or make service-role credentials available to browsers.
Provider API behavior is bounded by Config API-version fields and fake provider contract tests. Deployments must still run the live conformance suite before enabling a provider version, public-signup policy, or cross-project user-token trust branch.
Index ¶
- Constants
- Variables
- func SubjectIDStrategy() oidc.IdentityIDStrategy
- type AdminClient
- func (a *AdminClient) Activate(ctx context.Context, request auth.AccountLifecycleRequest) (result auth.AccountStateResult, err error)deprecated
- func (a *AdminClient) ActivateCoordinated(ctx context.Context, request auth.AccountLifecycleRequest, ...) (result auth.AccountStateResult, err error)
- func (a *AdminClient) ActivateExecutor(request auth.AccountLifecycleRequest) auth.ProviderOperationExecutor
- func (a *AdminClient) GetAccountState(ctx context.Context, request auth.AccountLifecycleRequest) (result auth.AccountStateResult, err error)
- func (a *AdminClient) Invite(ctx context.Context, request auth.InviteRequest) (result auth.ProviderDeliveryOutcome, err error)
- func (a *AdminClient) ListFactors(ctx context.Context, request auth.FactorListRequest) (result auth.ProviderFactorsResult, err error)
- func (a *AdminClient) RemoveFactor(ctx context.Context, request auth.FactorRemoveRequest) (result auth.ProviderOperationOutcome, err error)deprecated
- func (a *AdminClient) RemoveFactorCoordinated(ctx context.Context, request auth.FactorRemoveRequest, ...) (result auth.ProviderOperationOutcome, err error)
- func (a *AdminClient) RemoveFactorExecutor(request auth.FactorRemoveRequest) auth.ProviderOperationExecutor
- func (a *AdminClient) StartRecovery(ctx context.Context, request auth.RecoveryRequest) (result auth.ProviderDeliveryOutcome, err error)
- func (a *AdminClient) Suspend(ctx context.Context, request auth.AccountLifecycleRequest) (result auth.AccountStateResult, err error)deprecated
- func (a *AdminClient) SuspendCoordinated(ctx context.Context, request auth.AccountLifecycleRequest, ...) (result auth.AccountStateResult, err error)
- func (a *AdminClient) SuspendExecutor(request auth.AccountLifecycleRequest) auth.ProviderOperationExecutor
- type AuthorizationCSRFContext
- type AuthorizationCSRFVerifier
- type AuthorizationCSRFVerifierFunc
- type AuthorizationClientPolicy
- type AuthorizationService
- func (s *AuthorizationService) ApproveAuthorization(ctx context.Context, request auth.AuthorizationDecisionRequest) (auth.AuthorizationDecisionResult, error)
- func (s *AuthorizationService) DenyAuthorization(ctx context.Context, request auth.AuthorizationDecisionRequest) (auth.AuthorizationDecisionResult, error)
- func (s *AuthorizationService) GetAuthorizationDetails(ctx context.Context, request auth.AuthorizationDetailsRequest) (result auth.AuthorizationDetails, err error)
- type AuthorizationServiceConfig
- type ClaimsMapper
- type Client
- type ClientOption
- type Config
- func (c Config) Format(state fmt.State, _ rune)
- func (c Config) GoString() string
- func (c Config) LogValue() slog.Value
- func (c Config) MarshalJSON() ([]byte, error)
- func (c Config) MarshalText() ([]byte, error)
- func (c Config) OIDCConfig() (oidc.ProviderConfig, error)
- func (c Config) PrincipalMapper(allowedHookClaims ...string) (oidc.PrincipalMapper, error)
- func (c Config) ProviderSessionManagerConfig(base auth.ProviderSessionManagerConfig) (auth.ProviderSessionManagerConfig, error)
- func (c Config) ReturnURLAllowed(raw string) bool
- func (c Config) String() string
- func (c Config) Validate() error
- func (c Config) WithDefaults() Config
- type ErrorKind
- type ProviderError
- type RefreshTokenValidator
- type RetryPolicy
- type SessionClient
- func (s *SessionClient) ReconcileProviderRefresh(context.Context, auth.ProviderRefreshReconcileRequest) (auth.ProviderRefreshReconcileResult, error)
- func (s *SessionClient) RefreshProviderTokens(ctx context.Context, request auth.ProviderRefreshRequest) (auth.ProviderRefreshResult, error)
- func (s *SessionClient) RevokeProviderSession(ctx context.Context, request auth.ProviderRevocationRequest) (auth.ProviderRemoteRevocationOutcome, error)
- func (s *SessionClient) SignOut(ctx context.Context, tokens auth.ProviderTokenSet, scope SignOutScope) (auth.ProviderRemoteRevocationOutcome, error)
- type SignOutScope
Constants ¶
const ( ProviderKey = "supabase" DefaultAuthAPIVersion = "2024-01-01" DefaultOAuthAPIVersion = "2024-01-01" DefaultRequestTimeout = 10 * time.Second DefaultResponseBodyBytes = int64(1 << 20) )
const DefaultAuthorizationTTL = 15 * time.Minute
Variables ¶
var ( ErrRateLimited = errors.New("supabase: rate limited") ErrResponseTooLarge = errors.New("supabase: response exceeds configured limit") ErrAmbiguousMutation = errors.New("supabase: mutation result is ambiguous") )
var ErrInvalidConfig = errors.New("supabase: invalid configuration")
Functions ¶
func SubjectIDStrategy ¶
func SubjectIDStrategy() oidc.IdentityIDStrategy
SubjectIDStrategy returns the opt-in linker strategy that preserves a validated Supabase UUID subject as the local user ID.
Types ¶
type AdminClient ¶
type AdminClient struct {
// contains filtered or unexported fields
}
func NewAdminClient ¶
func NewAdminClient(client *Client) (*AdminClient, error)
func NewHardenedAdminClient ¶
func NewHardenedAdminClient(client *Client) (*AdminClient, error)
NewHardenedAdminClient requires coordinator-issued execution permits for provider mutations. New production compositions should use this constructor; NewAdminClient remains the explicitly low-level compatibility boundary.
func (*AdminClient) Activate
deprecated
func (a *AdminClient) Activate(ctx context.Context, request auth.AccountLifecycleRequest) (result auth.AccountStateResult, err error)
Activate is the low-level compatibility mutation.
Deprecated: use ActivateCoordinated through LifecycleCoordinator with a coordinator-issued permit.
func (*AdminClient) ActivateCoordinated ¶
func (a *AdminClient) ActivateCoordinated( ctx context.Context, request auth.AccountLifecycleRequest, permit auth.LifecycleExecutionPermit, ) (result auth.AccountStateResult, err error)
func (*AdminClient) ActivateExecutor ¶
func (a *AdminClient) ActivateExecutor( request auth.AccountLifecycleRequest, ) auth.ProviderOperationExecutor
func (*AdminClient) GetAccountState ¶
func (a *AdminClient) GetAccountState(ctx context.Context, request auth.AccountLifecycleRequest) (result auth.AccountStateResult, err error)
func (*AdminClient) Invite ¶
func (a *AdminClient) Invite(ctx context.Context, request auth.InviteRequest) (result auth.ProviderDeliveryOutcome, err error)
func (*AdminClient) ListFactors ¶
func (a *AdminClient) ListFactors(ctx context.Context, request auth.FactorListRequest) (result auth.ProviderFactorsResult, err error)
func (*AdminClient) RemoveFactor
deprecated
func (a *AdminClient) RemoveFactor(ctx context.Context, request auth.FactorRemoveRequest) (result auth.ProviderOperationOutcome, err error)
RemoveFactor is the low-level compatibility mutation.
Deprecated: use RemoveFactorCoordinated through LifecycleCoordinator with a coordinator-issued permit.
func (*AdminClient) RemoveFactorCoordinated ¶
func (a *AdminClient) RemoveFactorCoordinated( ctx context.Context, request auth.FactorRemoveRequest, permit auth.LifecycleExecutionPermit, ) (result auth.ProviderOperationOutcome, err error)
func (*AdminClient) RemoveFactorExecutor ¶
func (a *AdminClient) RemoveFactorExecutor( request auth.FactorRemoveRequest, ) auth.ProviderOperationExecutor
func (*AdminClient) StartRecovery ¶
func (a *AdminClient) StartRecovery(ctx context.Context, request auth.RecoveryRequest) (result auth.ProviderDeliveryOutcome, err error)
func (*AdminClient) Suspend
deprecated
func (a *AdminClient) Suspend(ctx context.Context, request auth.AccountLifecycleRequest) (result auth.AccountStateResult, err error)
Suspend is the low-level compatibility mutation.
Deprecated: use SuspendCoordinated through LifecycleCoordinator with a coordinator-issued permit.
func (*AdminClient) SuspendCoordinated ¶
func (a *AdminClient) SuspendCoordinated( ctx context.Context, request auth.AccountLifecycleRequest, permit auth.LifecycleExecutionPermit, ) (result auth.AccountStateResult, err error)
func (*AdminClient) SuspendExecutor ¶
func (a *AdminClient) SuspendExecutor( request auth.AccountLifecycleRequest, ) auth.ProviderOperationExecutor
type AuthorizationCSRFVerifier ¶
type AuthorizationCSRFVerifier interface {
VerifyAuthorizationCSRF(context.Context, AuthorizationCSRFContext) error
}
type AuthorizationCSRFVerifierFunc ¶
type AuthorizationCSRFVerifierFunc func(context.Context, AuthorizationCSRFContext) error
func (AuthorizationCSRFVerifierFunc) VerifyAuthorizationCSRF ¶
func (f AuthorizationCSRFVerifierFunc) VerifyAuthorizationCSRF(ctx context.Context, csrf AuthorizationCSRFContext) error
type AuthorizationService ¶
type AuthorizationService struct {
// contains filtered or unexported fields
}
func NewAuthorizationService ¶
func NewAuthorizationService(config AuthorizationServiceConfig) (*AuthorizationService, error)
func (*AuthorizationService) ApproveAuthorization ¶
func (s *AuthorizationService) ApproveAuthorization( ctx context.Context, request auth.AuthorizationDecisionRequest, ) (auth.AuthorizationDecisionResult, error)
func (*AuthorizationService) DenyAuthorization ¶
func (s *AuthorizationService) DenyAuthorization( ctx context.Context, request auth.AuthorizationDecisionRequest, ) (auth.AuthorizationDecisionResult, error)
func (*AuthorizationService) GetAuthorizationDetails ¶
func (s *AuthorizationService) GetAuthorizationDetails( ctx context.Context, request auth.AuthorizationDetailsRequest, ) (result auth.AuthorizationDetails, err error)
type AuthorizationServiceConfig ¶
type AuthorizationServiceConfig struct {
Client *Client
Clients map[string]AuthorizationClientPolicy
CSRFVerifier AuthorizationCSRFVerifier
DecisionProofKey auth.Secret
MaxTTL time.Duration
Clock func() time.Time
}
type ClaimsMapper ¶
ClaimsMapper normalizes Supabase-specific session and assurance claims after generic OIDC has validated both tokens. Only explicitly allowlisted app_metadata values are copied; user_metadata is never authoritative.
func (ClaimsMapper) MapPrincipal ¶
func (m ClaimsMapper) MapPrincipal( ctx context.Context, provider oidc.ProviderConfig, idToken auth.ValidatedTokenContext, accessToken *auth.ValidatedTokenContext, idClaims jwt.MapClaims, accessClaims jwt.MapClaims, userInfo map[string]any, ) (oidc.ValidatedProviderIdentity, error)
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(config Config, userTokens auth.UserTokenProvider, httpClient *http.Client, options ...ClientOption) (*Client, error)
type ClientOption ¶
type ClientOption func(*Client)
func WithActivityErrorHandler ¶
func WithActivityErrorHandler(handler func(context.Context, error)) ClientOption
WithActivityErrorHandler makes best-effort audit delivery failures visible without changing an already-completed provider operation's result.
func WithActivitySink ¶
func WithActivitySink(sink auth.ActivitySink) ClientOption
WithActivitySink records one best-effort audit event for every validated provider lifecycle operation. Persistence and retry remain host-owned.
func WithRetryPolicy ¶
func WithRetryPolicy(policy RetryPolicy) ClientOption
type Config ¶
type Config struct {
ProjectURL string
Issuer string
DiscoveryURL string
ClientID string
ClientSecret auth.Secret
TokenEndpointAuthMethod oidc.TokenEndpointAuthMethod
CallbackURL string
Scopes []string
IDTokenAudience []string
AccessTokenAudience []string
AllowedAlgorithms []string
AuthorizationUIURL string
AllowedReturnURLs []string
AdminCredential auth.Secret
PublishableKey auth.Secret
ManagementCredential auth.Secret
Environment string
// ProviderSessionDeployment is consulted only when explicitly preparing a
// ProviderSessionManagerConfig. Local-token OIDC and API clients do not
// require provider-session operations policy.
ProviderSessionDeployment auth.ProviderSessionDeployment
AuthAPIVersion string
OAuthAPIVersion string
AllowInsecureLoopback bool
RequestTimeout time.Duration
ResponseBodyBytes int64
}
func (Config) MarshalJSON ¶
func (Config) MarshalText ¶
func (Config) OIDCConfig ¶
func (c Config) OIDCConfig() (oidc.ProviderConfig, error)
func (Config) PrincipalMapper ¶
func (c Config) PrincipalMapper(allowedHookClaims ...string) (oidc.PrincipalMapper, error)
func (Config) ProviderSessionManagerConfig ¶
func (c Config) ProviderSessionManagerConfig( base auth.ProviderSessionManagerConfig, ) (auth.ProviderSessionManagerConfig, error)
ProviderSessionManagerConfig binds an explicitly selected Supabase deployment class to a matching provider-session manager configuration. Shared OIDC and API-client validation deliberately does not call this method.
func (Config) ReturnURLAllowed ¶
func (Config) WithDefaults ¶
type ProviderError ¶
type ProviderError struct {
Kind ErrorKind
Code string
StatusCode int
RequestID string
Retryable bool
Ambiguous bool
// contains filtered or unexported fields
}
func (*ProviderError) Error ¶
func (e *ProviderError) Error() string
func (*ProviderError) Unwrap ¶
func (e *ProviderError) Unwrap() error
type RefreshTokenValidator ¶
type RetryPolicy ¶
type SessionClient ¶
type SessionClient struct {
// contains filtered or unexported fields
}
func NewSessionClient ¶
func NewSessionClient(client *Client, validator RefreshTokenValidator) (*SessionClient, error)
func (*SessionClient) ReconcileProviderRefresh ¶
func (s *SessionClient) ReconcileProviderRefresh(context.Context, auth.ProviderRefreshReconcileRequest) (auth.ProviderRefreshReconcileResult, error)
func (*SessionClient) RefreshProviderTokens ¶
func (s *SessionClient) RefreshProviderTokens(ctx context.Context, request auth.ProviderRefreshRequest) (auth.ProviderRefreshResult, error)
func (*SessionClient) RevokeProviderSession ¶
func (s *SessionClient) RevokeProviderSession(ctx context.Context, request auth.ProviderRevocationRequest) (auth.ProviderRemoteRevocationOutcome, error)
func (*SessionClient) SignOut ¶
func (s *SessionClient) SignOut(ctx context.Context, tokens auth.ProviderTokenSet, scope SignOutScope) (auth.ProviderRemoteRevocationOutcome, error)
type SignOutScope ¶
type SignOutScope string
const ( SignOutCurrent SignOutScope = "local" SignOutAll SignOutScope = "global" SignOutNamed SignOutScope = "named" )