summaryrefslogtreecommitdiffstats
path: root/python/fatcat_web
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2019-01-02 17:58:15 -0800
committerBryan Newbold <bnewbold@robocracy.org>2019-01-02 17:58:15 -0800
commit10ddca2c2fd6b14bbd94fe57aed66a6de03e1777 (patch)
tree5dc7e5794210e4a6b9769dc899d288005325b182 /python/fatcat_web
parent25e6a55305b24218be76c9edfe3df0f88ce13234 (diff)
downloadfatcat-10ddca2c2fd6b14bbd94fe57aed66a6de03e1777.tar.gz
fatcat-10ddca2c2fd6b14bbd94fe57aed66a6de03e1777.zip
start on webface oauth2/oidc web auth
Diffstat (limited to 'python/fatcat_web')
-rw-r--r--python/fatcat_web/__init__.py12
-rw-r--r--python/fatcat_web/auth.py27
-rw-r--r--python/fatcat_web/routes.py13
3 files changed, 51 insertions, 1 deletions
diff --git a/python/fatcat_web/__init__.py b/python/fatcat_web/__init__.py
index 3c790e7a..f8b72fd0 100644
--- a/python/fatcat_web/__init__.py
+++ b/python/fatcat_web/__init__.py
@@ -2,6 +2,9 @@
from flask import Flask
from flask_uuid import FlaskUUID
from flask_debugtoolbar import DebugToolbarExtension
+from flask_login import LoginManager
+from authlib.flask.client import OAuth
+from loginpass import create_flask_blueprint, Gitlab
from raven.contrib.flask import Sentry
from web_config import Config
import fatcat_client
@@ -12,6 +15,10 @@ app.config.from_object(Config)
toolbar = DebugToolbarExtension(app)
FlaskUUID(app)
+login_manager = LoginManager()
+login_manager.init_app(app)
+oauth = OAuth(app)
+
# Grabs sentry config from SENTRY_DSN environment variable
sentry = Sentry(app)
@@ -19,4 +26,7 @@ conf = fatcat_client.Configuration()
conf.host = "http://localhost:9411/v0"
api = fatcat_client.DefaultApi(fatcat_client.ApiClient(conf))
-from fatcat_web import routes
+from fatcat_web import routes, auth
+
+gitlab_bp = create_flask_blueprint(Gitlab, oauth, auth.handle_oauth)
+app.register_blueprint(gitlab_bp, url_prefix='/auth/gitlab')
diff --git a/python/fatcat_web/auth.py b/python/fatcat_web/auth.py
new file mode 100644
index 00000000..f6672e87
--- /dev/null
+++ b/python/fatcat_web/auth.py
@@ -0,0 +1,27 @@
+
+from flask import Flask, render_template, send_from_directory, request, \
+ url_for, abort, g, redirect, jsonify, session
+from fatcat_web import login_manager
+
+
+# This will need to login/signup via fatcatd API, then set token in session
+def handle_oauth(remote, token, user_info):
+ print(remote)
+ if token:
+ print(remote.name, token)
+ if user_info:
+ # TODO: fetch api login/signup using user_info
+ print(user_info)
+ # TODO: write token and username to session
+ # TODO: call login_user(load_user(editor_id))
+ return redirect("/")
+ raise some_error
+
+
+@login_manager.user_loader
+def load_user(editor_id):
+ # NOTE: this should look for extra info in session, and update the user
+ # object with that. If session isn't loaded/valid, should return None
+ user = UserMixin()
+ user.id = editor_id
+ return user
diff --git a/python/fatcat_web/routes.py b/python/fatcat_web/routes.py
index 998697bc..51533a2f 100644
--- a/python/fatcat_web/routes.py
+++ b/python/fatcat_web/routes.py
@@ -367,6 +367,19 @@ def search():
return render_template('release_search.html', query=query, fulltext_only=fulltext_only)
+### Auth ####################################################################
+
+@app.route('/login')
+def login():
+ # show the user a list of login options
+ return render_template('release_search.html', query=query, fulltext_only=fulltext_only)
+
+@app.route('/login')
+def logout():
+ # TODO: clear extra session info
+ logout_user()
+ return render_template('logout.html')
+
### Static Routes ###########################################################
@app.errorhandler(404)