diff --git a/CHANGELOG.md b/CHANGELOG.md index 33614e4..976e529 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,15 +10,18 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [1.0.0](https://github.com/python-social-auth/social-app-flask/releases/tag/1.0.0) - 2017-01-22 ### Changed + - Remove usage of set/get current strategy methods ## [0.1.0](https://github.com/python-social-auth/social-app-flask/releases/tag/0.1.0) - 2016-12-28 ### Added + - Added flask-login dependency ## [0.0.1](https://github.com/python-social-auth/social-app-flask/releases/tag/0.0.1) - 2016-11-27 ### Changed + - Split from the monolitic [python-social-auth](https://github.com/omab/python-social-auth) codebase diff --git a/setup.py b/setup.py index 1097bfd..62aaa4b 100644 --- a/setup.py +++ b/setup.py @@ -1,36 +1,39 @@ -# -*- coding: utf-8 -*- """Setup file for easy installation""" -from os.path import join, dirname + +from os.path import dirname, join + from setuptools import setup def long_description(): - return open(join(dirname(__file__), 'README.md')).read() + return open(join(dirname(__file__), "README.md")).read() + def load_requirements(): - return open(join(dirname(__file__), 'requirements.txt')).readlines() + return open(join(dirname(__file__), "requirements.txt")).readlines() + setup( - name='social-auth-app-flask', - version=__import__('social_flask').__version__, - author='Matias Aguirre', - author_email='matiasaguirre@gmail.com', - description='Python Social Authentication, Flask integration.', - license='BSD', - keywords='flask, social auth', - url='https://github.com/python-social-auth/social-app-flask', - packages=['social_flask'], + name="social-auth-app-flask", + version=__import__("social_flask").__version__, + author="Matias Aguirre", + author_email="matiasaguirre@gmail.com", + description="Python Social Authentication, Flask integration.", + license="BSD", + keywords="flask, social auth", + url="https://github.com/python-social-auth/social-app-flask", + packages=["social_flask"], long_description=long_description(), install_requires=load_requirements(), classifiers=[ - 'Development Status :: 4 - Beta', - 'Topic :: Internet', - 'License :: OSI Approved :: BSD License', - 'Intended Audience :: Developers', - 'Environment :: Web Environment', - 'Programming Language :: Python', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3' + "Development Status :: 4 - Beta", + "Topic :: Internet", + "License :: OSI Approved :: BSD License", + "Intended Audience :: Developers", + "Environment :: Web Environment", + "Programming Language :: Python", + "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 3", ], - zip_safe=False + zip_safe=False, ) diff --git a/social_flask/__init__.py b/social_flask/__init__.py index 1f356cc..5becc17 100644 --- a/social_flask/__init__.py +++ b/social_flask/__init__.py @@ -1 +1 @@ -__version__ = '1.0.0' +__version__ = "1.0.0" diff --git a/social_flask/routes.py b/social_flask/routes.py index 48bc4a8..350bf9a 100644 --- a/social_flask/routes.py +++ b/social_flask/routes.py @@ -1,33 +1,35 @@ -from flask import g, Blueprint, request +from flask import Blueprint, g, request from flask_login import login_required, login_user - from social_core.actions import do_auth, do_complete, do_disconnect -from social_flask.utils import psa +from social_flask.utils import psa -social_auth = Blueprint('social', __name__) +social_auth = Blueprint("social", __name__) -@social_auth.route('/login//', methods=('GET', 'POST')) -@psa('social.complete') +@social_auth.route("/login//", methods=("GET", "POST")) +@psa("social.complete") def auth(backend): return do_auth(g.backend) -@social_auth.route('/complete//', methods=('GET', 'POST')) -@psa('social.complete') +@social_auth.route("/complete//", methods=("GET", "POST")) +@psa("social.complete") def complete(backend, *args, **kwargs): - """Authentication complete view, override this view if transaction - management doesn't suit your needs.""" - return do_complete(g.backend, login=do_login, user=g.user, - *args, **kwargs) - - -@social_auth.route('/disconnect//', methods=('POST',)) -@social_auth.route('/disconnect///', - methods=('POST',)) -@social_auth.route('/disconnect///', - methods=('POST',)) + """ + Authentication complete view, override this view if transaction + management doesn't suit your needs. + """ + return do_complete(g.backend, login=do_login, user=g.user, *args, **kwargs) + + +@social_auth.route("/disconnect//", methods=("POST",)) +@social_auth.route( + "/disconnect///", methods=("POST",) +) +@social_auth.route( + "/disconnect///", methods=("POST",) +) @login_required @psa() def disconnect(backend, association_id=None): @@ -36,10 +38,12 @@ def disconnect(backend, association_id=None): def do_login(backend, user, social_user): - 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 + 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) diff --git a/social_flask/strategy.py b/social_flask/strategy.py index a6d93ca..b81cb79 100644 --- a/social_flask/strategy.py +++ b/social_flask/strategy.py @@ -1,8 +1,14 @@ -from flask import current_app, request, redirect, make_response, session, \ - render_template, render_template_string - -from social_core.utils import build_absolute_uri +from flask import ( + current_app, + make_response, + redirect, + render_template, + render_template_string, + request, + session, +) from social_core.strategy import BaseStrategy, BaseTemplateStrategy +from social_core.utils import build_absolute_uri class FlaskTemplateStrategy(BaseTemplateStrategy): @@ -23,7 +29,7 @@ def request_data(self, merge=True): if merge: data = request.form.copy() data.update(request.args) - elif request.method == 'POST': + elif request.method == "POST": data = request.form else: data = request.args @@ -37,7 +43,7 @@ def redirect(self, url): def html(self, content): response = make_response(content) - response.headers['Content-Type'] = 'text/html;charset=UTF-8' + response.headers["Content-Type"] = "text/html;charset=UTF-8" return response def session_get(self, name, default=None): diff --git a/social_flask/template_filters.py b/social_flask/template_filters.py index 95cfe31..9837c73 100644 --- a/social_flask/template_filters.py +++ b/social_flask/template_filters.py @@ -1,25 +1,28 @@ from flask import g, request - from social_core.backends.utils import user_backends_data + from social_flask.utils import get_helper def backends(): - """Load Social Auth current user data to context under the key 'backends'. - Will return the output of social.backends.utils.user_backends_data.""" + """ + Load Social Auth current user data to context under the key 'backends'. + Will return the output of social.backends.utils.user_backends_data. + """ return { - 'backends': user_backends_data(g.user, - get_helper('AUTHENTICATION_BACKENDS'), - get_helper('STORAGE', do_import=True)) + "backends": user_backends_data( + g.user, + get_helper("AUTHENTICATION_BACKENDS"), + get_helper("STORAGE", do_import=True), + ) } def login_redirect(): """Load current redirect to context.""" - value = request.form.get('next', '') or \ - request.args.get('next', '') + value = request.form.get("next", "") or request.args.get("next", "") return { - 'REDIRECT_FIELD_NAME': 'next', - 'REDIRECT_FIELD_VALUE': value, - 'REDIRECT_QUERYSTRING': value and ('next=' + value) or '' + "REDIRECT_FIELD_NAME": "next", + "REDIRECT_FIELD_VALUE": value, + "REDIRECT_QUERYSTRING": (value and ("next=" + value)) or "", } diff --git a/social_flask/utils.py b/social_flask/utils.py index 3fe3069..3ed5c51 100644 --- a/social_flask/utils.py +++ b/social_flask/utils.py @@ -1,31 +1,28 @@ from functools import wraps -from flask import current_app, url_for, g - -from social_core.utils import module_member, setting_name, get_strategy +from flask import current_app, g, url_for from social_core.backends.utils import get_backend - +from social_core.utils import get_strategy, module_member, setting_name DEFAULTS = { - 'STORAGE': 'social_flask_sqlalchemy.models.FlaskStorage', - 'STRATEGY': 'social_flask.strategy.FlaskStrategy' + "STORAGE": "social_flask_sqlalchemy.models.FlaskStorage", + "STRATEGY": "social_flask.strategy.FlaskStrategy", } + def get_helper(name, do_import=False): - config = current_app.config.get(setting_name(name), - DEFAULTS.get(name, None)) + config = current_app.config.get(setting_name(name), DEFAULTS.get(name)) if do_import: config = module_member(config) return config def load_strategy(): - return get_strategy(get_helper('STRATEGY'), - get_helper('STORAGE')) + return get_strategy(get_helper("STRATEGY"), get_helper("STORAGE")) def load_backend(strategy, name, redirect_uri, *args, **kwargs): - backends = get_helper('AUTHENTICATION_BACKENDS') + backends = get_helper("AUTHENTICATION_BACKENDS") Backend = get_backend(backends, name) return Backend(strategy=strategy, redirect_uri=redirect_uri) @@ -35,11 +32,14 @@ def decorator(func): @wraps(func) def wrapper(backend, *args, **kwargs): uri = redirect_uri - if uri and not uri.startswith('/'): + if uri and not uri.startswith("/"): uri = url_for(uri, backend=backend) g.strategy = load_strategy() - g.backend = load_backend(g.strategy, backend, redirect_uri=uri, - *args, **kwargs) + g.backend = load_backend( + g.strategy, backend, redirect_uri=uri, *args, **kwargs + ) return func(backend, *args, **kwargs) + return wrapper + return decorator