diff options
Diffstat (limited to 'uploader/oauth2/client.py')
-rw-r--r-- | uploader/oauth2/client.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/uploader/oauth2/client.py b/uploader/oauth2/client.py index 6e101ae..f20af4a 100644 --- a/uploader/oauth2/client.py +++ b/uploader/oauth2/client.py @@ -1,9 +1,9 @@ """OAuth2 client utilities.""" -from urllib.parse import urljoin from datetime import datetime, timedelta +from urllib.parse import urljoin, urlparse import requests -from flask import current_app as app +from flask import request, current_app as app from pymonad.either import Left, Right @@ -99,3 +99,19 @@ def oauth2_client(): return session.user_token().either( lambda _notok: __client__(None), __client__) + + +def user_logged_in(): + """Check whether the user has logged in.""" + suser = session.session_info()["user"] + # return suser["logged_in"] and suser["token"].is_right() + return False + +def authserver_authorise_uri(): + req_baseurl = urlparse(request.base_url, scheme=request.scheme) + host_uri = f"{req_baseurl.scheme}://{req_baseurl.netloc}/" + return urljoin( + authserver_uri(), + "auth/authorise?response_type=code" + f"&client_id={oauth2_clientid()}" + f"&redirect_uri={urljoin(host_uri, 'oauth2/code')}") |