mirror of
https://github.com/Ponce/slackbuilds
synced 2024-11-16 19:50:19 +01:00
python/Flask-Security: Added (Simple security for Flask apps).
Signed-off-by: Willy Sudiarto Raharjo <willysr@slackbuilds.org>
This commit is contained in:
parent
0ec91175bd
commit
ec47491876
5 changed files with 218 additions and 0 deletions
90
python/Flask-Security/Flask-Security.SlackBuild
Normal file
90
python/Flask-Security/Flask-Security.SlackBuild
Normal file
|
@ -0,0 +1,90 @@
|
|||
#!/bin/sh
|
||||
|
||||
# Slackware build script for Flask-Security
|
||||
|
||||
# Copyright 2017 Nikos Giotis <nikos.giotis@gmail.com>
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use of this script, with or without modification, is
|
||||
# permitted provided that the following conditions are met:
|
||||
#
|
||||
# 1. Redistributions of this script must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
|
||||
# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
||||
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
||||
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
PRGNAM=Flask-Security
|
||||
VERSION=${VERSION:-1.7.5}
|
||||
BUILD=${BUILD:-1}
|
||||
TAG=${TAG:-_SBo}
|
||||
|
||||
if [ -z "$ARCH" ]; then
|
||||
case "$( uname -m )" in
|
||||
i?86) ARCH=i586 ;;
|
||||
arm*) ARCH=arm ;;
|
||||
*) ARCH=$( uname -m ) ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
CWD=$(pwd)
|
||||
TMP=${TMP:-/tmp/SBo}
|
||||
PKG=$TMP/package-$PRGNAM
|
||||
OUTPUT=${OUTPUT:-/tmp}
|
||||
|
||||
if [ "$ARCH" = "i586" ]; then
|
||||
SLKCFLAGS="-O2 -march=i586 -mtune=i686"
|
||||
LIBDIRSUFFIX=""
|
||||
elif [ "$ARCH" = "i686" ]; then
|
||||
SLKCFLAGS="-O2 -march=i686 -mtune=i686"
|
||||
LIBDIRSUFFIX=""
|
||||
elif [ "$ARCH" = "x86_64" ]; then
|
||||
SLKCFLAGS="-O2 -fPIC"
|
||||
LIBDIRSUFFIX="64"
|
||||
else
|
||||
SLKCFLAGS="-O2"
|
||||
LIBDIRSUFFIX=""
|
||||
fi
|
||||
|
||||
set -e
|
||||
|
||||
rm -rf $PKG
|
||||
mkdir -p $TMP $PKG $OUTPUT
|
||||
cd $TMP
|
||||
rm -rf $PRGNAM-$VERSION
|
||||
tar xvf $CWD/$PRGNAM-$VERSION.tar.gz
|
||||
cd $PRGNAM-$VERSION
|
||||
|
||||
# Patch for token-loader
|
||||
# see https://github.com/mattupstate/flask-security/pull/558/
|
||||
cat $CWD/token-loader.patch | patch -p1
|
||||
|
||||
chown -R root:root .
|
||||
find -L . \
|
||||
\( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \
|
||||
-o -perm 511 \) -exec chmod 755 {} \; -o \
|
||||
\( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \
|
||||
-o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;
|
||||
|
||||
python setup.py install --root=$PKG
|
||||
|
||||
find $PKG -print0 | xargs -0 file | grep -e "executable" -e "shared object" | grep ELF \
|
||||
| cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true
|
||||
|
||||
mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
|
||||
cp -a README.rst $PKG/usr/doc/$PRGNAM-$VERSION
|
||||
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild
|
||||
|
||||
mkdir -p $PKG/install
|
||||
cat $CWD/slack-desc > $PKG/install/slack-desc
|
||||
|
||||
cd $PKG
|
||||
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz}
|
10
python/Flask-Security/Flask-Security.info
Normal file
10
python/Flask-Security/Flask-Security.info
Normal file
|
@ -0,0 +1,10 @@
|
|||
PRGNAM="Flask-Security"
|
||||
VERSION="1.7.5"
|
||||
HOMEPAGE="https://github.com/mattupstate/flask-security"
|
||||
DOWNLOAD="https://pypi.python.org/packages/5c/c2/7c2311e599690b6b4a55346900523e33ce61e81be4d01fa231d2fc8ea12a/Flask-Security-1.7.5.tar.gz"
|
||||
MD5SUM="98a0237a04d39a951e9129311d6dc4e0"
|
||||
DOWNLOAD_x86_64=""
|
||||
MD5SUM_x86_64=""
|
||||
REQUIRES="Flask-Login Flask-Mail Flask-Principal Flask-WTF itsdangerous passlib"
|
||||
MAINTAINER="Nikos Giotis"
|
||||
EMAIL="nikos.giotis@gmail.com"
|
3
python/Flask-Security/README
Normal file
3
python/Flask-Security/README
Normal file
|
@ -0,0 +1,3 @@
|
|||
Flask-Security
|
||||
|
||||
Quick and simple security for Flask applications
|
19
python/Flask-Security/slack-desc
Normal file
19
python/Flask-Security/slack-desc
Normal file
|
@ -0,0 +1,19 @@
|
|||
# HOW TO EDIT THIS FILE:
|
||||
# The "handy ruler" below makes it easier to edit a package description.
|
||||
# Line up the first '|' above the ':' following the base package name, and
|
||||
# the '|' on the right side marks the last column you can put a character in.
|
||||
# You must make exactly 11 lines for the formatting to be correct. It's also
|
||||
# customary to leave one space after the ':' except on otherwise blank lines.
|
||||
|
||||
|-----handy-ruler------------------------------------------------------|
|
||||
Flask-Security: Flask-Security (Simple security for Flask apps)
|
||||
Flask-Security:
|
||||
Flask-Security: Flask-Security quickly adds security features to your Flask
|
||||
Flask-Security: application.
|
||||
Flask-Security:
|
||||
Flask-Security: https://github.com/mattupstate/flask-security
|
||||
Flask-Security:
|
||||
Flask-Security:
|
||||
Flask-Security:
|
||||
Flask-Security:
|
||||
Flask-Security:
|
96
python/Flask-Security/token-loader.patch
Normal file
96
python/Flask-Security/token-loader.patch
Normal file
|
@ -0,0 +1,96 @@
|
|||
From 01a0d62b7e5246867d456de5515a1fe09eb0f2ed Mon Sep 17 00:00:00 2001
|
||||
From: Alan Hamlett <alan.hamlett@gmail.com>
|
||||
Date: Thu, 27 Oct 2016 15:04:07 +0200
|
||||
Subject: [PATCH 1/2] replace token loader with request loader to fix #81
|
||||
|
||||
---
|
||||
flask_security/core.py | 12 ++++++++++--
|
||||
flask_security/decorators.py | 10 +---------
|
||||
tests/test_common.py | 2 +-
|
||||
3 files changed, 12 insertions(+), 12 deletions(-)
|
||||
|
||||
diff --git a/flask_security/core.py b/flask_security/core.py
|
||||
index 3256668..3bcef52 100644
|
||||
--- a/flask_security/core.py
|
||||
+++ b/flask_security/core.py
|
||||
@@ -191,7 +191,15 @@ def _user_loader(user_id):
|
||||
return _security.datastore.find_user(id=user_id)
|
||||
|
||||
|
||||
-def _token_loader(token):
|
||||
+def _request_loader(request):
|
||||
+ header_key = _security.token_authentication_header
|
||||
+ args_key = _security.token_authentication_key
|
||||
+ header_token = request.headers.get(header_key, None)
|
||||
+ token = request.args.get(args_key, header_token)
|
||||
+ if request.get_json(silent=True):
|
||||
+ if not isinstance(request.json, list):
|
||||
+ token = request.json.get(args_key, token)
|
||||
+
|
||||
try:
|
||||
data = _security.remember_token_serializer.loads(token, max_age=_security.token_max_age)
|
||||
user = _security.datastore.find_user(id=data[0])
|
||||
@@ -223,7 +231,7 @@ def _get_login_manager(app, anonymous_user):
|
||||
lm.anonymous_user = anonymous_user or AnonymousUser
|
||||
lm.login_view = '%s.login' % cv('BLUEPRINT_NAME', app=app)
|
||||
lm.user_loader(_user_loader)
|
||||
- lm.token_loader(_token_loader)
|
||||
+ lm.request_loader(_request_loader)
|
||||
|
||||
if cv('FLASH_MESSAGES', app=app):
|
||||
lm.login_message, lm.login_message_category = cv('MSG_LOGIN', app=app)
|
||||
diff --git a/flask_security/decorators.py b/flask_security/decorators.py
|
||||
index 89e62e8..81fa2f0 100644
|
||||
--- a/flask_security/decorators.py
|
||||
+++ b/flask_security/decorators.py
|
||||
@@ -58,15 +58,7 @@ def _get_unauthorized_view():
|
||||
|
||||
|
||||
def _check_token():
|
||||
- header_key = _security.token_authentication_header
|
||||
- args_key = _security.token_authentication_key
|
||||
- header_token = request.headers.get(header_key, None)
|
||||
- token = request.args.get(args_key, header_token)
|
||||
- if request.get_json(silent=True):
|
||||
- if not isinstance(request.json, list):
|
||||
- token = request.json.get(args_key, token)
|
||||
-
|
||||
- user = _security.login_manager.token_callback(token)
|
||||
+ user = _security.login_manager.request_callback(request)
|
||||
|
||||
if user and user.is_authenticated:
|
||||
app = current_app._get_current_object()
|
||||
diff --git a/tests/test_common.py b/tests/test_common.py
|
||||
index e884ab5..531090f 100644
|
||||
--- a/tests/test_common.py
|
||||
+++ b/tests/test_common.py
|
||||
@@ -271,7 +271,7 @@ def test_remember_token(client):
|
||||
assert b'profile' in response.data
|
||||
|
||||
|
||||
-def test_token_loader_does_not_fail_with_invalid_token(client):
|
||||
+def test_request_loader_does_not_fail_with_invalid_token(client):
|
||||
c = Cookie(version=0, name='remember_token', value='None', port=None,
|
||||
port_specified=False, domain='www.example.com',
|
||||
domain_specified=False, domain_initial_dot=False, path='/',
|
||||
|
||||
From 6d56450a2b88c7196eeeba503b8e4ae3cdc857aa Mon Sep 17 00:00:00 2001
|
||||
From: Alan Hamlett <alan.hamlett@gmail.com>
|
||||
Date: Fri, 28 Oct 2016 00:45:51 +0200
|
||||
Subject: [PATCH 2/2] remove max version requirement from Flask-Login
|
||||
|
||||
---
|
||||
requirements.txt | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/requirements.txt b/requirements.txt
|
||||
index c2df730..bd79ce4 100644
|
||||
--- a/requirements.txt
|
||||
+++ b/requirements.txt
|
||||
@@ -1,5 +1,5 @@
|
||||
Flask>=0.9
|
||||
-Flask-Login>=0.3.0,<0.4
|
||||
+Flask-Login>=0.3.0
|
||||
Flask-Mail>=0.7.3
|
||||
Flask-Principal>=0.3.3
|
||||
Flask-WTF>=0.8
|
Loading…
Reference in a new issue