Exceptions¶
Social Auth exposes structured exceptions so applications can choose recovery without matching provider descriptions or exception messages.
Catch SocialAuthBaseException for all Social Auth failures, including
configuration errors. Catch AuthException for authentication-flow failures.
Both retain their existing inheritance, including ValueError. Configuration
errors inherit directly from SocialAuthBaseException.
Exception families¶
AuthConfigurationErrorMissing or invalid settings, unavailable backends, or unsupported features.
AuthInputErrorMissing or invalid request or application input.
AuthSessionErrorMissing authentication context, state mismatch, or a different initiating user.
AuthResponseErrorMalformed provider responses or failed signature, claim, nonce, or expiry validation.
AuthCredentialErrorRejected credentials, rejected authorization codes, revoked tokens, or required reauthentication.
AuthPolicyErrorApplication authentication, membership, or disconnect policy rejection.
AuthAssociationErrorLocal account conflicts or unsafe identifier migration.
AuthProviderErrorConnection, timeout, TLS, rate-limit, availability, or HTTP failures.
AuthCanceledExplicit authorization cancellation or refusal.
AuthUnknownErrorAuthentication failures without a known classification.
Structured attributes¶
Each exception exposes code, source, stage, and recovery. Codes
are stable machine-readable strings; messages and diagnostic descriptions are
not part of the classification contract.
source identifies the failing boundary, not who is responsible:
configuration, request, session, provider_response,
local_policy, storage, or unknown.
stage identifies the operation: begin, callback, token_exchange,
token_validation, user_info, pipeline, refresh, disconnect,
or unknown. Custom integrations should supply the stage at the raise site.
recovery suggests an action: none, correct_input, restart_login,
reauthenticate, retry_later, check_provider_profile,
use_existing_account, or contact_administrator. These hints do not
perform retries or redirects and do not determine whether to report a failure.
Optional attributes are backend, parameter, claim, provider_code,
status_code, and retry_after. retry_after preserves the provider’s
HTTP header; applications must interpret it before using it.
str(exception) and exception.args contain a safe default message.
Provider descriptions are available separately in detail. context is
an explicitly supplied mapping for diagnostic identifiers, such as user ID and
provider UID. Original exceptions remain available through exception chaining.
Do not send diagnostics, raw responses, or identifying context to client URLs
or flash messages. Do not log tokens, cookies, or full authentication assertions.
public_metadata() returns only error_code, error_source,
error_stage, and error_recovery.
from social_core.exceptions import AuthResponseError, AuthException
if "sub" not in claims:
raise AuthResponseError(
backend, code="missing_claim", claim="sub", stage="token_validation"
)
try:
authenticate()
except AuthException as error:
if error.code == "response_expired":
show_restart_login_message()
else:
show_generic_authentication_message()
Application-specific codes should have a namespace, for example
myapp.registration_disabled. Explicitly set their source and recovery.
Unknown codes use the family’s safe default message and metadata. Never derive
a code from a free-form message.
Reason codes¶
Defaults are listed below. A raise site can override source or recovery when its operation supplies more precise information.
Code |
Source |
Suggested recovery |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Provider failures¶
HTTP status alone does not establish cancellation, expired credentials, or a local policy rejection. Shared HTTP handling retains status and structured provider codes. Unknown provider codes remain provider errors.
For OAuth, invalid_client is a configuration failure and invalid_grant
is credential rejection. The latter does not establish expiry. Explicit
access_denied indicates authorization refusal. HTTP 429 and server errors
receive retry-later guidance; TLS verification failures require administrator
attention without suggesting that verification be disabled.
Migration from legacy exceptions¶
This is a breaking change. SocialAuthBaseException and AuthException
remain available for broad catches. AuthCanceled and AuthUnknownError
also remain available, so catches of these types can be retained. Removed names
have no aliases or wrappers. Update custom backends, pipelines, and catches of
removed types together with the library upgrade.
Previous exception |
Replacement |
|---|---|
|
Choose response, credential, session, policy, or provider failure from the actual cause. |
|
Input errors for request data; configuration errors for settings; response errors for provider fields. |
|
Session errors with |
|
|
|
|
|
Local policy errors; session errors for user mismatch; provider errors for HTTP rejection. |
|
Association errors with an explicit identity, username, email, or migration-conflict code. |
|
Credential errors with |
|
Provider errors distinguishing connection, timeout, TLS, rate limit, and availability. |
|
Credential error with |
|
Policy error with |
|
Response error with |
|
Configuration error with |
Strategy/configuration errors / |
Configuration errors with missing/invalid settings or |
Previously, AuthStateMissing meant missing session state, while missing
callback state raised AuthMissingParameter. Preserve that distinction when
migrating: use a session error for missing saved state and an input error for a
missing callback parameter.
Construct failures with a backend (or None where unavailable) and keyword
metadata. Keep provider descriptions in diagnostic positional arguments.
For example, replace AuthTokenError(backend, "Signature has expired") at a
confirmed expiry boundary with:
AuthResponseError(
backend,
"Signature has expired",
code="response_expired",
stage="token_validation",
)
Do not translate that text into a code elsewhere in the application.