diff options
author | Frederick Muriuki Muriithi | 2024-03-06 14:57:54 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-03-06 14:57:54 +0300 |
commit | b63b91cf52c148c6f7091e3845bb3fdb11052d62 (patch) | |
tree | 8542d4860383a8e169e08f38f93320f7eb0036e8 /gn2/wqflask/oauth2 | |
parent | b14fefe25f1536e2376efa6b0dba9dce33609725 (diff) | |
download | genenetwork2-b63b91cf52c148c6f7091e3845bb3fdb11052d62.tar.gz |
Use AUTH_SERVER_URL setting from flask.current_app not gn2.utility.tools
Diffstat (limited to 'gn2/wqflask/oauth2')
-rw-r--r-- | gn2/wqflask/oauth2/checks.py | 2 | ||||
-rw-r--r-- | gn2/wqflask/oauth2/data.py | 19 | ||||
-rw-r--r-- | gn2/wqflask/oauth2/users.py | 11 |
3 files changed, 13 insertions, 19 deletions
diff --git a/gn2/wqflask/oauth2/checks.py b/gn2/wqflask/oauth2/checks.py index 070e956d..4233e376 100644 --- a/gn2/wqflask/oauth2/checks.py +++ b/gn2/wqflask/oauth2/checks.py @@ -27,7 +27,7 @@ def require_oauth2(func): client = OAuth2Session( oauth2_clientid(), oauth2_clientsecret(), token=token) resp = client.get( - urljoin(AUTH_SERVER_URL, "auth/user/")) + urljoin(authserver_uri(), "auth/user/")) user_details = resp.json() if not user_details.get("error", False): return func(*args, **kwargs) diff --git a/gn2/wqflask/oauth2/data.py b/gn2/wqflask/oauth2/data.py index a1dfdf95..29d68be0 100644 --- a/gn2/wqflask/oauth2/data.py +++ b/gn2/wqflask/oauth2/data.py @@ -15,14 +15,13 @@ from gn2.wqflask.oauth2.request_utils import with_flash_error from gn2.jobs import jobs from .ui import render_ui from .request_utils import process_error -from .client import oauth2_get, oauth2_post +from .client import oauth2_get, oauth2_post, authserver_uri data = Blueprint("data", __name__) def __search_mrna__(query, template, **kwargs): - from gn2.utility.tools import AUTH_SERVER_URL species_name = kwargs["species_name"] - search_uri = urljoin(AUTH_SERVER_URL, "auth/data/search") + search_uri = urljoin(authserver_uri(), "auth/data/search") datasets = oauth2_get( "auth/data/search", json = { @@ -45,9 +44,8 @@ def __selected_datasets__(): request.form.get("selected", [])) def __search_genotypes__(query, template, **kwargs): - from gn2.utility.tools import AUTH_SERVER_URL species_name = kwargs["species_name"] - search_uri = urljoin(AUTH_SERVER_URL, "auth/data/search") + search_uri = urljoin(authserver_uri(), "auth/data/search") datasets = oauth2_get( "auth/data/search", json = { @@ -61,7 +59,7 @@ def __search_genotypes__(query, template, **kwargs): return render_ui(template, search_uri=search_uri, **datasets, **kwargs) def __search_phenotypes__(query, template, **kwargs): - from gn2.utility.tools import GN_SERVER_URL, AUTH_SERVER_URL + from gn2.utility.tools import GN_SERVER_URL page = int(request.args.get("page", 1)) per_page = int(request.args.get("per_page", 50)) selected_traits = request.form.getlist("selected_traits") @@ -71,10 +69,10 @@ def __search_phenotypes__(query, template, **kwargs): template, traits=[], per_page=per_page, query=query, selected_traits=selected_traits, search_results=search_results, search_endpoint=urljoin( - AUTH_SERVER_URL, "auth/data/search"), - gn_server_url = AUTH_SERVER_URL, + authserver_uri(), "auth/data/search"), + gn_server_url = authserver_uri(), results_endpoint=urljoin( - AUTH_SERVER_URL, + authserver_uri(), f"auth/data/search/phenotype/{job_id}"), **kwargs) return oauth2_get("auth/data/search", json={ @@ -124,7 +122,6 @@ def json_search_mrna() -> Response: @data.route("/phenotype/search", methods=["POST"]) def json_search_phenotypes() -> Response: """Search for phenotypes.""" - from gn2.utility.tools import AUTH_SERVER_URL form = request.json def __handle_error__(err): error = process_error(err) @@ -138,7 +135,7 @@ def json_search_phenotypes() -> Response: "query": form.get("query", ""), "per_page": int(form.get("per_page", 50)), "page": int(form.get("page", 1)), - "auth_server_uri": AUTH_SERVER_URL, + "auth_server_uri": authserver_uri(), "selected_traits": form.get("selected_traits", []) }).either(__handle_error__, jsonify) diff --git a/gn2/wqflask/oauth2/users.py b/gn2/wqflask/oauth2/users.py index 12d07d0c..894cce5b 100644 --- a/gn2/wqflask/oauth2/users.py +++ b/gn2/wqflask/oauth2/users.py @@ -11,7 +11,7 @@ from . import client from . import session from .ui import render_ui from .checks import require_oauth2, user_logged_in -from .client import oauth2_get, oauth2_post, oauth2_client +from .client import oauth2_get, oauth2_post, oauth2_client, authserver_uri from .request_utils import ( user_details, request_error, process_error, with_flash_error) @@ -65,7 +65,6 @@ def request_add_to_group() -> Response: @users.route("/login", methods=["GET", "POST"]) def login(): """Route to allow users to sign up.""" - from gn2.utility.tools import AUTH_SERVER_URL next_endpoint=request.args.get("next", False) if request.method == "POST": @@ -73,7 +72,7 @@ def login(): client = oauth2_client() try: token = client.fetch_token( - urljoin(AUTH_SERVER_URL, "auth/token"), + urljoin(authserver_uri(), "auth/token"), username=form.get("email_address"), password=form.get("password"), grant_type="password") @@ -101,10 +100,9 @@ def login(): @users.route("/logout", methods=["GET", "POST"]) def logout(): - from gn2.utility.tools import AUTH_SERVER_URL if user_logged_in(): resp = oauth2_client().revoke_token( - urljoin(AUTH_SERVER_URL, "auth/revoke")) + urljoin(authserver_uri(), "auth/revoke")) the_session = session.session_info() if not bool(the_session["masquerading"]): # Normal session - clear and go back. @@ -124,7 +122,6 @@ def logout(): @users.route("/register", methods=["GET", "POST"]) def register_user(): - from gn2.utility.tools import AUTH_SERVER_URL if user_logged_in(): next_endpoint=request.args.get("next", "/") flash(("You cannot register a new user while logged in. " @@ -137,7 +134,7 @@ def register_user(): form = request.form response = requests.post( - urljoin(AUTH_SERVER_URL, "auth/user/register"), + urljoin(authserver_uri(), "auth/user/register"), data = { "user_name": form.get("user_name"), "email": form.get("email_address"), |