Kunal commited on
Commit ·
bc03319
1
Parent(s): a03c760
update auth.py
Browse files- src/auth.py +3 -4
src/auth.py
CHANGED
|
@@ -27,8 +27,9 @@ class MALAuth:
|
|
| 27 |
self.error = None
|
| 28 |
|
| 29 |
def start_oauth_flow(self):
|
| 30 |
-
# Only generate new code_verifier if not already in session_state
|
| 31 |
-
|
|
|
|
| 32 |
st.session_state.code_verifier = secrets.token_urlsafe(64)
|
| 33 |
st.session_state.code_challenge = st.session_state.code_verifier # 'plain' method
|
| 34 |
|
|
@@ -42,12 +43,10 @@ class MALAuth:
|
|
| 42 |
f"code_challenge={self.code_challenge}&"
|
| 43 |
f"redirect_uri={REDIRECT_URI}"
|
| 44 |
)
|
| 45 |
-
# Use a button to open the auth link in the same tab
|
| 46 |
st.write('') # spacing
|
| 47 |
st.link_button("Click here to authenticate with MyAnimeList", auth_url)
|
| 48 |
|
| 49 |
# Streamlit Community Cloud: handle redirect via query params
|
| 50 |
-
query_params = st.query_params
|
| 51 |
if "code" in query_params:
|
| 52 |
self.auth_code = query_params["code"][0] if isinstance(query_params["code"], list) else query_params["code"]
|
| 53 |
return self.auth_code, None
|
|
|
|
| 27 |
self.error = None
|
| 28 |
|
| 29 |
def start_oauth_flow(self):
|
| 30 |
+
# Only generate new code_verifier if not already in session_state or if code param is not present
|
| 31 |
+
query_params = st.query_params
|
| 32 |
+
if "code" not in query_params:
|
| 33 |
st.session_state.code_verifier = secrets.token_urlsafe(64)
|
| 34 |
st.session_state.code_challenge = st.session_state.code_verifier # 'plain' method
|
| 35 |
|
|
|
|
| 43 |
f"code_challenge={self.code_challenge}&"
|
| 44 |
f"redirect_uri={REDIRECT_URI}"
|
| 45 |
)
|
|
|
|
| 46 |
st.write('') # spacing
|
| 47 |
st.link_button("Click here to authenticate with MyAnimeList", auth_url)
|
| 48 |
|
| 49 |
# Streamlit Community Cloud: handle redirect via query params
|
|
|
|
| 50 |
if "code" in query_params:
|
| 51 |
self.auth_code = query_params["code"][0] if isinstance(query_params["code"], list) else query_params["code"]
|
| 52 |
return self.auth_code, None
|