[Python-modules-commits] [python-social-auth] 37/61: Fix flask remember-me functionality

Wolfgang Borgert debacle at moszumanska.debian.org
Sat Dec 24 15:14:05 UTC 2016


This is an automated email from the git hooks/post-receive script.

debacle pushed a commit to tag v0.2.13
in repository python-social-auth.

commit 4e6e0952bafe918e5d6471a87717482750c46d1f
Author: Matías Aguirre <matiasaguirre at gmail.com>
Date:   Fri Aug 7 20:03:05 2015 -0300

    Fix flask remember-me functionality
---
 docs/configuration/flask.rst    | 26 ++++++++++++++++++++++++++
 social/apps/flask_app/routes.py |  9 +++++----
 2 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/docs/configuration/flask.rst b/docs/configuration/flask.rst
index bc364cf..fc7ada3 100644
--- a/docs/configuration/flask.rst
+++ b/docs/configuration/flask.rst
@@ -101,6 +101,32 @@ handlers to these::
             return {'user': None}
 
 
+Remembering sessions
+--------------------
+
+The users session can be remembered when specified on login. The common
+implementation for this feature is to pass a parameter from the login form
+(``remember_me``, ``keep``, etc), to flag the action. Flask-Login_ will mark
+the session as persistent if told so.
+
+python-social-auth_ will check for a given name (``keep``) by default, but
+since providers won't pass parameters back to the application, the value must
+be persisted in the session before the authentication process happens.
+
+So, the following setting is required for this to work::
+
+    SOCIAL_AUTH_FIELDS_STORED_IN_SESSION = ['keep']
+
+It's possible to override the default name with this setting::
+
+    SOCIAL_AUTH_REMEMBER_SESSION_NAME = 'remember_me'
+
+Don't use the value ``remember`` since that will clash with Flask-Login_ which
+pops the value from the session.
+
+Then just pass the parameter ``keep=1`` as a GET or POST parameter.
+
+
 Exceptions handling
 -------------------
 
diff --git a/social/apps/flask_app/routes.py b/social/apps/flask_app/routes.py
index 0d0578c..6c1eec7 100644
--- a/social/apps/flask_app/routes.py
+++ b/social/apps/flask_app/routes.py
@@ -36,9 +36,10 @@ def disconnect(backend, association_id=None):
 
 
 def do_login(backend, user, social_user):
-    remember = backend.strategy.session_get('remember') or \
-               request.cookies.get('remember') or \
-               request.args.get('remember') or \
-               request.form.get('remember') or \
+    name = backend.strategy.setting('REMEMBER_SESSION_NAME', 'keep')
+    remember = backend.strategy.session_get(name) or \
+               request.cookies.get(name) or \
+               request.args.get(name) or \
+               request.form.get(name) or \
                False
     return login_user(user, remember=remember)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-social-auth.git



More information about the Python-modules-commits mailing list