TEMPLATE_CONTEXT_PROCESSORS = (
...
+ 'social_auth.context_processors.social_auth_by_name_backends',
+ 'social_auth.context_processors.social_auth_backends',
'social_auth.context_processors.social_auth_by_type_backends',
)
- check `social_auth.context_processors`.
+ * `social_auth_by_name_backends`:
+ Adds a `social_auth` dict where each key is a provider name and its value
+ is a UserSocialAuth instance if user has associated an account with that
+ provider, otherwise `None`.
+
+ * `social_auth_backends`:
+ Adds a `social_auth` dict with keys are `associated, `not_associated` and
+ `backends`. `associated` key is a list of `UserSocialAuth` instances
+ associated with current user. `not_associated` is a list of providers names
+ that the current user doesn't have any association yet. `backends` holds
+ the list of backend names supported.
+
+ * `social_auth_by_type_backends`:
+ Simiar to `social_auth_backends` but each value is grouped by backend type
+ `openid`, `oauth2` and `oauth`.
+
+ Check `social_auth.context_processors` for details.
+
+ **Note**: `social_auth_backends` and `social_auth_by_type_backends` don't
+ play nice together.
- Sync database to create needed models::
TEMPLATE_CONTEXT_PROCESSORS = (
...
+ 'social_auth.context_processors.social_auth_by_name_backends',
+ 'social_auth.context_processors.social_auth_backends',
'social_auth.context_processors.social_auth_by_type_backends',
)
- check `social_auth.context_processors`.
+ * `social_auth_by_name_backends`:
+ Adds a `social_auth` dict where each key is a provider name and its value
+ is a UserSocialAuth instance if user has associated an account with that
+ provider, otherwise `None`.
+
+ * `social_auth_backends`:
+ Adds a `social_auth` dict with keys are `associated, `not_associated` and
+ `backends`. `associated` key is a list of `UserSocialAuth` instances
+ associated with current user. `not_associated` is a list of providers names
+ that the current user doesn't have any association yet. `backends` holds
+ the list of backend names supported.
+
+ * `social_auth_by_type_backends`:
+ Simiar to `social_auth_backends` but each value is grouped by backend type
+ `openid`, `oauth2` and `oauth`.
+
+ Check `social_auth.context_processors` for details.
+
+ **Note**: `social_auth_backends` and `social_auth_by_type_backends` don't
+ play nice together.
- Sync database to create needed models::
"""
keys = get_backends().keys()
accounts = dict(zip(keys, [None] * len(keys)))
+ user = request.user
- if isinstance(request.user, User) and request.user.is_authenticated():
- for associated in request.user.social_auth.all():
- accounts[associated.provider.replace('-', '_')] = associated
+ if isinstance(user, User) and user.is_authenticated():
+ accounts.update((assoc.provider.replace('-', '_'), assoc)
+ for assoc in user.social_auth.all())
return {'social_auth': accounts}
get_backends, OpenIdAuth, BaseOAuth, BaseOAuth2
result = defaultdict(list)
+ backends = get_backends()
for item in items:
- backend = get_backends()[key(item)]
+ backend = backends[key(item)]
if issubclass(backend, OpenIdAuth):
result['openid'].append(item)
elif issubclass(backend, BaseOAuth2):