aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-12-29 04:08:02 +0300
committerFrederick Muriuki Muriithi2022-12-29 04:08:02 +0300
commitbb19d605c30a3dd473c4a6e11a8b2022aca66b3f (patch)
treebcead9a8e4237621bb5ee5a6843ffb39f1fa1329
parent4f5972799832d747080606cd6550d33f98f144ff (diff)
downloadgenenetwork2-bb19d605c30a3dd473c4a6e11a8b2022aca66b3f.tar.gz
auth: Redirect on login and cleanup
* wqflask/wqflask/oauth2/routes.py: remove unused imports. Add placeholder endpoint "/register-client" * wqflask/wqflask/templates/oauth2/login.html: enable redirect to specific endpoints
-rw-r--r--wqflask/wqflask/oauth2/routes.py16
-rw-r--r--wqflask/wqflask/templates/oauth2/login.html7
2 files changed, 18 insertions, 5 deletions
diff --git a/wqflask/wqflask/oauth2/routes.py b/wqflask/wqflask/oauth2/routes.py
index a72501c4..a94d919b 100644
--- a/wqflask/wqflask/oauth2/routes.py
+++ b/wqflask/wqflask/oauth2/routes.py
@@ -1,12 +1,10 @@
"""Routes for the OAuth2 auth system in GN3"""
-import uuid
from urllib.parse import urljoin
-import redis
from authlib.integrations.requests_client import OAuth2Session
from authlib.integrations.base_client.errors import OAuthError
from flask import (
- flash, request, session, redirect, Blueprint, render_template,
+ flash, request, session, url_for, redirect, Blueprint, render_template,
current_app as app)
from .checks import require_oauth2, user_logged_in
@@ -16,6 +14,8 @@ oauth2 = Blueprint("oauth2", __name__)
@oauth2.route("/login", methods=["GET", "POST"])
def login():
"""Route to allow users to sign up."""
+ next_endpoint=request.args.get("next", False)
+
if request.method == "POST":
config = app.config
form = request.form
@@ -35,9 +35,11 @@ def login():
return render_template("oauth2/login.html")
if user_logged_in():
+ if next_endpoint:
+ return redirect(url_for(next_endpoint))
return redirect("/")
- return render_template("oauth2/login.html")
+ return render_template("oauth2/login.html", next_endpoint=next_endpoint)
@oauth2.route("/logout", methods=["GET", "POST"])
@@ -47,3 +49,9 @@ def logout():
session.pop(key, default=None)
return redirect("/")
+
+@oauth2.route("/register-client", methods=["GET", "POST"])
+@require_oauth2
+def register_client():
+ """Register an OAuth2 client."""
+ return "USER IS LOGGED IN AND SUCCESSFULLY ACCESSED THIS ENDPOINT!"
diff --git a/wqflask/wqflask/templates/oauth2/login.html b/wqflask/wqflask/templates/oauth2/login.html
index d8745bad..6288b630 100644
--- a/wqflask/wqflask/templates/oauth2/login.html
+++ b/wqflask/wqflask/templates/oauth2/login.html
@@ -4,7 +4,12 @@
<div class="container" style="min-width: 1250px;">
<h3>Sign in here.</h3>
- <form class="form-horizontal" action="{{url_for('oauth2.login')}}"
+ <form class="form-horizontal"
+ {%if next_endpoint%}
+ action="{{url_for('oauth2.login', next=next_endpoint)}}"
+ {%else%}
+ action="{{url_for('oauth2.login')}}"
+ {%endif%}
method="POST" id="oauth2-login-form">
<fieldset>
<legend>Sign in with Genenetwork</legend>