Skip to main content

SocialApp

Represents a social application (OAuth client) configured for authentication.

Fields

CharField
The provider type (e.g., “google”, “github”, “saml”).Max length: 30 characters
CharField
For providers that support subproviders (OpenID Connect, SAML), this ID identifies the specific instance. Social accounts originating from this app will have their provider field set to provider_id if available, otherwise provider.Max length: 200 characters
Optional: Yes
CharField
Human-readable name for the application.Max length: 40 characters
CharField
OAuth client ID, app ID, or consumer key.Max length: 191 characters
CharField
API secret, client secret, or consumer secret.Max length: 191 characters
Optional: Yes
CharField
Additional key field for providers that require it.Max length: 191 characters
Optional: Yes
JSONField
Additional provider-specific settings stored as JSON.Default: {}
ManyToManyField
Associated Django sites where this app can be used. Only available when django.contrib.sites is enabled.Related model: sites.Site
Optional: Yes

Methods

get_provider()

Returns the provider instance for this social app.
HttpRequest
The Django request object.
Provider
The provider instance configured with this app.
Example:

Manager Methods

objects.on_site()

Filters social apps available for the current site.
HttpRequest
The Django request object.
QuerySet
Social apps configured for the current site, or all apps if sites framework is disabled.
Example:

SocialAccount

Represents a user’s account with a social provider.

Fields

ForeignKey
The local user account associated with this social account.Related model: AUTH_USER_MODEL
On delete: CASCADE
CharField
The provider identifier. For accounts from a SocialApp, this equals the app’s provider_id if available, otherwise provider.Max length: 200 characters
CharField
The unique identifier for the user at the provider. This is the provider’s user ID.Max length: Configurable via SOCIALACCOUNT_UID_MAX_LENGTH (default: 191)
Unique: Together with provider
DateTimeField
Timestamp of the last login using this social account.Auto-updated: Yes
DateTimeField
Timestamp when this social account was first connected.Auto-created: Yes
JSONField
Additional data from the provider (profile information, etc.).Default: {}

Methods

authenticate()

Authenticates and returns the user associated with this social account.
User
The authenticated user object.
Example:

get_profile_url()

Returns the profile URL for this account on the social provider’s site.
str
The profile URL, or empty string if not available.
Example:

get_avatar_url()

Returns the avatar/profile picture URL from the provider.
str
The avatar URL, or empty string if not available.
Example:

get_provider()

Returns the provider instance for this social account.
HttpRequest
Optional Django request object.
Provider
The provider instance.
Example:

get_provider_account()

Returns the provider-specific account wrapper with additional functionality.
ProviderAccount
Provider-specific account object.
Example:

SocialToken

Stores OAuth tokens for social accounts.

Fields

ForeignKey
The social application this token is for.Related model: SocialApp
On delete: SET_NULL
Optional: Yes
ForeignKey
The social account this token belongs to.Related model: SocialAccount
On delete: CASCADE
TextField
The OAuth token. For OAuth1, this is the oauth_token. For OAuth2, this is the access token.
TextField
The OAuth token secret. For OAuth1, this is the oauth_token_secret. For OAuth2, this is the refresh token.Optional: Yes
DateTimeField
When the access token expires.Optional: Yes

Meta

tuple
Combination of app and account must be unique.
Example:

SocialLogin

Represents a social user in the process of being logged in. This is a non-model class used during authentication flow.

Attributes

SocialAccount
The social account being logged in. May be unsaved.
User
The local user being logged in. May be unsaved.
SocialToken
Optional access token from the authentication handshake.
List[EmailAddress]
Email addresses retrieved from the provider.
dict
State preserved during authentication. May be included in URLs, so do not store secrets here.
Provider
The provider instance handling this login.
str
Phone number retrieved from the provider, if available.
bool
Whether the phone number has been verified by the provider.

Methods

__init__()

Creates a new SocialLogin instance. Example:

connect()

Connects this social account to an existing user.
HttpRequest
The Django request object.
User
The user to connect this social account to.
Example:

save()

Saves the social account and user to the database.
HttpRequest
The Django request object.
bool
Whether this is a connection to an existing user.Default: False
Example:

lookup()

Looks up the existing local user account this social login points to, if any. Updates self.user if found. Example:

serialize()

Serializes the social login to a dictionary.
dict
Dictionary containing all social login data.
Example:

deserialize()

Deserializes a social login from a dictionary.
dict
Dictionary containing serialized social login data.
SocialLogin
The deserialized SocialLogin instance.
Example:

get_redirect_url()

Returns the URL to redirect to after login.
HttpRequest
The Django request object.
str
The redirect URL, or None.
Example:

stash_state()

Stashes state in the session and returns a state ID.
HttpRequest
The Django request object.
dict
State dictionary to stash. If None, extracts state from request.
str
State ID that can be used to retrieve the state later.
Example:

unstash_state()

Retrieves and removes the last stashed state from the session.
HttpRequest
The Django request object.
dict
The unstashed state dictionary.
Raises:
  • PermissionDenied if no state is found.
Example:

Properties

is_existing

Returns False if this represents a temporary account not yet saved to the database. Example:

is_headless

Returns True if this is a headless (API-based) authentication flow. Example: