SOCIAL_AUTH_EXPIRATION = 'expires'
to and use such setting name where expiration times are returned. View that
- completes login process will set session expiration time to this value if
- it's present.
+ completes login process will set session expiration time using this name if
+ it's present or 'expires' by default. Expiration time saving can be disabled
+ setting::
+
+ SOCIAL_AUTH_SESSION_EXPIRATION = False
- It's possible to override the used User model if needed::
if user and getattr(user, 'is_active', True):
login(request, user)
- # set session expiration date if present
- social_user = user.social_auth.get(provider=backend.AUTH_BACKEND.name)
- if social_user.expiration_delta():
- request.session.set_expiry(social_user.expiration_delta())
+ if getattr(settings, 'SOCIAL_AUTH_SESSION_EXPIRATION', True):
+ # Set session expiration date if present and not disabled by setting
+ backend_name = backend.AUTH_BACKEND.name
+ social_user = user.social_auth.get(provider=backend_name)
+ if social_user.expiration_delta():
+ request.session.set_expiry(social_user.expiration_delta())
url = request.session.pop(REDIRECT_FIELD_NAME, '') or \
getattr(settings, 'LOGIN_REDIRECT_URL', '')
else: