Once the application was installed (check Installation) define the following settings to enable the application behavior. Also check the sections dedicated to each framework for detailed instructions.
Almost all settings are prefixed with SOCIAL_AUTH_, there are some exceptions for Django framework like AUTHENTICATION_BACKENDS.
All settings can be defined per-backend by adding the backend name to the setting name like SOCIAL_AUTH_TWITTER_LOGIN_URL. Settings discovery is done by reducing the name starting with backend setting, then app setting and finally global setting, for example:
SOCIAL_AUTH_TWITTER_LOGIN_URL
SOCIAL_AUTH_LOGIN_URL
LOGIN_URL
The backend name is generated from the name attribute from the backend class by uppercasing it and replacing - with _.
Setup needed OAuth keys (see OAuth section for details):
SOCIAL_AUTH_TWITTER_KEY = 'foobar'
SOCIAL_AUTH_TWITTER_SECRET = 'bazqux'
OpenId backends don’t require keys usually, but some need some API Key to call any API on the provider. Check Backends sections for details.
Register the backends you plan to use, on Django framework use the usual AUTHENTICATION_BACKENDS settings, for others, define SOCIAL_AUTH_AUTHENTICATION_BACKENDS:
SOCIAL_AUTH_AUTHENTICATION_BACKENDS = (
'social.backends.open_id.OpenIdAuth',
'social.backends.google.GoogleOpenId',
'social.backends.google.GoogleOAuth2',
'social.backends.google.GoogleOAuth',
'social.backends.twitter.TwitterOAuth',
'social.backends.yahoo.YahooOpenId',
...
)
These URLs are used on different steps of the auth process, some for successful results and others for error situations.
Successful URLs will default to SOCIAL_AUTH_LOGIN_URL while error URLs will fallback to SOCIAL_AUTH_LOGIN_ERROR_URL.
UserSocialAuth instances keep a reference to the User model of your project, since this is not know, the User model must be configured by a setting:
SOCIAL_AUTH_USER_MODEL = 'foo.bar.User'
User model must have a username and email field, these are required.
Also an is_authenticated and is_active boolean flags are recommended, these can be methods if necessary (must return True or False). If the model lacks them a True value is assumed.
Some databases impose limitations to indexes columns (like MySQL InnoDB), these limitations won’t play nice on some UserSocialAuth fields. To avoid such error define some of the following settings.
Some providers return an username, others just an Id or email or first and last names. The application tries to build a meaningful username when possible but defaults to generating one if needed.
An UUID is appended to usernames in case of collisions. Here are some settings to control usernames generation.
Some providers accept particular GET parameters that produce different results during the auth process, usually used to show different dialog types (mobile version, etc).
You can send extra parameters on auth process by defining settings per backend, example to request Facebook to show Mobile authorization page, define:
FACEBOOK_AUTH_EXTRA_ARGUMENTS = {'display': 'touch'}
For other providers, just define settings in the form:
<uppercase backend name>_AUTH_EXTRA_ARGUMENTS = {...}
Also, you can send extra parameters on request token process by defining settings in the same way explained above but with this other suffix:
<uppercase backend name>_REQUEST_TOKEN_EXTRA_ARGUMENTS = {...}
The application issues several redirects and API calls, this following settings allow some tweaks to the behavior of these.
Any urllib2.urlopen call will be performed with the default timeout value, to change it without affecting the global socket timeout define this setting (the value specifies timeout seconds).
urllib2.urlopen uses socket.getdefaulttimeout() value by default, so setting socket.setdefaulttimeout(...) will affect urlopen when this setting is not defined, otherwise this setting takes precedence. Also this might affect other places in Django.
timeout argument was introduced in python 2.6 according to urllib2 documentation
Registration can be limited to a set of users identified by their email address or domain name. To white-list just set any of these settings:
If you want to store extra parameters from POST or GET in session, like it was made for next parameter, define this setting with the parameter names.
In this case foo field’s value will be stored when user follows this link <a href="{% url socialauth_begin 'github' %}?foo=bar">...</a>.
Disconnect is an side-effect operation and should be done by POST method only, some CSRF protection is encouraged (and enforced on Django app). Ensure that any call to /disconnect/<backend>/ or /disconnect/<backend>/<id>/ is done using POST.