Skip to content

Commit

Permalink
chore: apply pre-commit fixes
Browse files Browse the repository at this point in the history
Automated update of shared files from the social-core repository, see
https://github.com/python-social-auth/.github/blob/main/repo-sync.py
  • Loading branch information
nijel committed Jan 10, 2025
1 parent 17a2fd8 commit 4019470
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 79 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
47 changes: 25 additions & 22 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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='[email protected]',
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="[email protected]",
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,
)
2 changes: 1 addition & 1 deletion social_flask/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.0.0'
__version__ = "1.0.0"
54 changes: 29 additions & 25 deletions social_flask/routes.py
Original file line number Diff line number Diff line change
@@ -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/<string:backend>/', methods=('GET', 'POST'))
@psa('social.complete')
@social_auth.route("/login/<string:backend>/", methods=("GET", "POST"))
@psa("social.complete")
def auth(backend):
return do_auth(g.backend)


@social_auth.route('/complete/<string:backend>/', methods=('GET', 'POST'))
@psa('social.complete')
@social_auth.route("/complete/<string:backend>/", 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/<string:backend>/', methods=('POST',))
@social_auth.route('/disconnect/<string:backend>/<int:association_id>/',
methods=('POST',))
@social_auth.route('/disconnect/<string:backend>/<string:association_id>/',
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/<string:backend>/", methods=("POST",))
@social_auth.route(
"/disconnect/<string:backend>/<int:association_id>/", methods=("POST",)
)
@social_auth.route(
"/disconnect/<string:backend>/<string:association_id>/", methods=("POST",)
)
@login_required
@psa()
def disconnect(backend, association_id=None):
Expand All @@ -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)
18 changes: 12 additions & 6 deletions social_flask/strategy.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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
Expand All @@ -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):
Expand Down
25 changes: 14 additions & 11 deletions social_flask/template_filters.py
Original file line number Diff line number Diff line change
@@ -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 "",
}
28 changes: 14 additions & 14 deletions social_flask/utils.py
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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

0 comments on commit 4019470

Please sign in to comment.