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
Optional: Yes
provider field set to provider_id if available, otherwise provider.Max length: 200 charactersOptional: 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
Optional: Yes
CharField
Additional key field for providers that require it.Max length: 191 characters
Optional: Yes
Optional: Yes
JSONField
Additional provider-specific settings stored as JSON.Default:
{}ManyToManyField
Associated Django sites where this app can be used. Only available when
Optional: Yes
django.contrib.sites is enabled.Related model: sites.SiteOptional: Yes
Methods
get_provider()
HttpRequest
The Django request object.
Provider
The provider instance configured with this app.
Manager Methods
objects.on_site()
HttpRequest
The Django request object.
QuerySet
Social apps configured for the current site, or all apps if sites framework is disabled.
SocialAccount
Represents a user’s account with a social provider.Fields
ForeignKey
The local user account associated with this social account.Related model:
On delete: CASCADE
AUTH_USER_MODELOn 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 charactersCharField
The unique identifier for the user at the provider. This is the provider’s user ID.Max length: Configurable via
Unique: Together with
SOCIALACCOUNT_UID_MAX_LENGTH (default: 191)Unique: Together with
providerDateTimeField
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()
User
The authenticated user object.
get_profile_url()
str
The profile URL, or empty string if not available.
get_avatar_url()
str
The avatar URL, or empty string if not available.
get_provider()
HttpRequest
Optional Django request object.
Provider
The provider instance.
get_provider_account()
ProviderAccount
Provider-specific account object.
SocialToken
Stores OAuth tokens for social accounts.Fields
ForeignKey
The social application this token is for.Related model:
On delete: SET_NULL
Optional: Yes
SocialAppOn delete: SET_NULL
Optional: Yes
ForeignKey
The social account this token belongs to.Related model:
On delete: CASCADE
SocialAccountOn 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: YesDateTimeField
When the access token expires.Optional: Yes
Meta
tuple
Combination of
app and account must be unique.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__()
connect()
HttpRequest
The Django request object.
User
The user to connect this social account to.
save()
HttpRequest
The Django request object.
bool
Whether this is a connection to an existing user.Default: False
lookup()
self.user if found.
Example:
serialize()
dict
Dictionary containing all social login data.
deserialize()
dict
Dictionary containing serialized social login data.
SocialLogin
The deserialized SocialLogin instance.
get_redirect_url()
HttpRequest
The Django request object.
str
The redirect URL, or None.
stash_state()
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.
unstash_state()
HttpRequest
The Django request object.
dict
The unstashed state dictionary.
PermissionDeniedif no state is found.
Properties
is_existing
False if this represents a temporary account not yet saved to the database.
Example:
is_headless
True if this is a headless (API-based) authentication flow.
Example:
