From baae6e097c248419630801f0a23ba1b899248ed0 Mon Sep 17 00:00:00 2001 From: maximstewart Date: Sat, 13 Feb 2021 19:29:36 -0600 Subject: [PATCH] Logic fix, README additions --- README.md | 1 + src/dropper/routes/__init__.py | 1 + src/dropper/routes/pages/Login.py | 29 +++++++++++++++++++++++++++++ src/dropper/static/NOTES.txt | 3 +-- src/{start.sh => linux-start.sh} | 0 src/socket_run.sh | 16 ++++++++++++++++ 6 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 src/dropper/routes/pages/Login.py rename src/{start.sh => linux-start.sh} (100%) create mode 100755 src/socket_run.sh diff --git a/README.md b/README.md index ffe821a..59aeed1 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ Dropper is an uploading/downloading application to push and pull data from devic * Set the fields in static/google-api-data.json file to use the google drive picker api. * You will need Keycloak setup to use this application. * DNS over HTTPS can affect hosts file usage so make sure to disable that if using Firefox and editing hosts file. +* If using HTTPS, you will need to add your certificate information to httplib2's (located in your venv folder under site-packages) 'cacerts.txt' file. Otherwise, you'll get "itsdangerous.exc.BadSignature:" error trying to login or out. # Setup You will need Keycloak setup to use this application. The file 'client_secrets.json' has the predefined structure setup so you can use it for reference- modify accordingly. If you use the same realms and clients in Keycloak, you'll still need to change the 'client_secret' key; the one shown is an example of what you need to get from Keycloak (CHANGE and KEEP this SECRET if using on a public facing site!). In addition, use the hosts file on your computer to setup redirects for 'www.ssoapps.com' (Keycloak) and 'www.dropper.com' (Dropper App). diff --git a/src/dropper/routes/__init__.py b/src/dropper/routes/__init__.py index ffe39af..d4fa9fa 100644 --- a/src/dropper/routes/__init__.py +++ b/src/dropper/routes/__init__.py @@ -1 +1,2 @@ from . import Routes +from .pages import Login diff --git a/src/dropper/routes/pages/Login.py b/src/dropper/routes/pages/Login.py new file mode 100644 index 0000000..ee5b8d5 --- /dev/null +++ b/src/dropper/routes/pages/Login.py @@ -0,0 +1,29 @@ +# Python imports + +# Lib imports +from flask import request, render_template, flash, redirect, url_for + +# App imports +from ... import app, oidc +from ...utils import MessageHandler # Get simple message processor + + +msgHandler = MessageHandler() + + +@app.route('/login', methods=['GET', 'POST']) +@oidc.require_login +def login(): + return redirect("/") + + +@app.route('/logout', methods=['GET', 'POST']) +@oidc.require_login +def logout(): + oidc.logout() + flash("Logged out successfully!", "success") + # NOTE: Need to redirect to logout on OIDC server to end session there too. + # If not, we can hit login url again and get same token until it expires. + return redirect( oidc.client_secrets.get('issuer') + + '/protocol/openid-connect/logout?redirect_uri=' + + app.config['APP_REDIRECT_URI']) diff --git a/src/dropper/static/NOTES.txt b/src/dropper/static/NOTES.txt index 0d4f101..0637a08 100644 --- a/src/dropper/static/NOTES.txt +++ b/src/dropper/static/NOTES.txt @@ -1,2 +1 @@ -[ -] +[] \ No newline at end of file diff --git a/src/start.sh b/src/linux-start.sh similarity index 100% rename from src/start.sh rename to src/linux-start.sh diff --git a/src/socket_run.sh b/src/socket_run.sh new file mode 100755 index 0000000..8491f53 --- /dev/null +++ b/src/socket_run.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# set -o xtrace ## To debug scripts +# set -o errexit ## To exit on error +# set -o errunset ## To exit if a variable is referenced but not set + + +function main() { + SCRIPTPATH="$( cd "$(dirname "")" >/dev/null 2>&1 ; pwd -P )" + cd "${SCRIPTPATH}" + echo "Working Dir: " $(pwd) + mkdir /tmp/apps + source "../venv/bin/activate" + gunicorn --bind unix:/tmp/apps/dropper.sock wsgi:app -p app.pid +} +main $@;