diff --git a/setup.py b/setup.py index 805f6421..087d6bdb 100644 --- a/setup.py +++ b/setup.py @@ -49,7 +49,7 @@ # solvebio-recipes only available in python3 extras_requires = {} else: - extra['use_2to3'] = True + extra['use_2to3'] = False with open('README.md') as f: long_description = f.read() diff --git a/solvebio/contrib/streamlit/solvebio_auth.py b/solvebio/contrib/streamlit/solvebio_auth.py index 10332371..5b1d78b8 100644 --- a/solvebio/contrib/streamlit/solvebio_auth.py +++ b/solvebio/contrib/streamlit/solvebio_auth.py @@ -8,6 +8,9 @@ from httpx_oauth.oauth2 import BaseOAuth2 +import logging +logger = logging.getLogger('solvebio') + class SolveBioOAuth2(BaseOAuth2[Dict[str, Any]]): """Class implementing OAuth2 for SolveBio API""" @@ -16,6 +19,7 @@ class SolveBioOAuth2(BaseOAuth2[Dict[str, Any]]): SOLVEBIO_URL = os.environ.get('SOLVEBIO_URL', 'https://my.solvebio.com') OAUTH2_TOKEN_URL = "/v1/oauth2/token" OAUTH2_REVOKE_TOKEN_URL = "/v1/oauth2/revoke_token" + OAUTH2_REVOKE_TOKEN_AUTH = "client_secret_basic" def __init__(self, client_id, client_secret, name="solvebio"): super().__init__( @@ -26,6 +30,7 @@ def __init__(self, client_id, client_secret, name="solvebio"): revoke_token_endpoint=urljoin( solvebio.api_host, self.OAUTH2_REVOKE_TOKEN_URL ), + revocation_endpoint_auth_method=self.OAUTH2_REVOKE_TOKEN_AUTH, name=name, ) @@ -38,4 +43,5 @@ def get_authorization_url(self, redirect_uri): "redirect_uri": redirect_uri, } - return "{}/authorize?{}".format(self.authorize_endpoint, urlencode(params)) + auth_url = "{}/authorize?{}".format(self.authorize_endpoint, urlencode(params)) + return auth_url diff --git a/solvebio/contrib/streamlit/solvebio_streamlit.py b/solvebio/contrib/streamlit/solvebio_streamlit.py index cb0a40c1..7adb3cee 100644 --- a/solvebio/contrib/streamlit/solvebio_streamlit.py +++ b/solvebio/contrib/streamlit/solvebio_streamlit.py @@ -4,7 +4,10 @@ import streamlit as st import solvebio -from solvebio_auth import SolveBioOAuth2 +from .solvebio_auth import SolveBioOAuth2 + +import logging +logger = logging.getLogger('solvebio') class SolveBioStreamlit: @@ -12,20 +15,20 @@ class SolveBioStreamlit: # App settings loaded from environment variables or .env file CLIENT_ID = os.environ.get("CLIENT_ID", "Application (client) Id") - CLIENT_SECRET = os.environ.get("CLIENT_SECRET", "Application (client) secret") + CLIENT_SECRET = os.environ.get("CLIENT_SECRET") APP_URL = os.environ.get("APP_URL", "http://localhost:5000") def solvebio_login_component(self, authorization_url): - """Streamlit component for logging into SolveBio""" + """Streamlit component for logging into QuartzBio""" st.title("Secure Streamlit App") st.write( """

- Log in to SolveBio to continue + Log in to QuartzBio EDP to continue

- This app requires a SolveBio account.
- Contact Support + This app requires a QuartzBio account.
+ Contact Support """.format( authorization_url ), @@ -48,6 +51,8 @@ def get_token_from_session(self): def wrap(self, streamlit_app): """SolveBio OAuth2 wrapper around streamlit app""" + logger.info("Wrapping streamlit application") + # SolveBio OAuth2 client oauth_client = SolveBioOAuth2(self.CLIENT_ID, self.CLIENT_SECRET) authorization_url = oauth_client.get_authorization_url( @@ -56,17 +61,17 @@ def wrap(self, streamlit_app): # Authorization token from Streamlit session state oauth_token = self.get_token_from_session() + debug_message = str(oauth_token)[:4] if oauth_token else "" + logger.debug("OAuth token: " + debug_message) if oauth_token is None: # User is not authrized to use the app try: # Trying to get the authorization token from the url if successfully authorized - code = st.experimental_get_query_params()["code"] + code = st.query_params.get("code") # Remove authorization token from the url params - params = {} - st.experimental_set_query_params(**params) - + st.query_params.clear() except: # Display SolveBio login until user is successfully authorized self.solvebio_login_component(authorization_url) @@ -76,10 +81,11 @@ def wrap(self, streamlit_app): oauth_token = asyncio.run( oauth_client.get_access_token(code, self.APP_URL) ) - except: + except Exception as e: st.error( - "This account is not allowed or page was refreshed. Please login again." + "This account is not allowed or page was refreshed. Please login again.", ) + st.error(e) self.solvebio_login_component(authorization_url) else: # Check if token has expired: