Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-XT committed Jun 13, 2024
1 parent c3c4cb6 commit b9e38ee
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 90 deletions.
31 changes: 31 additions & 0 deletions components/Auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,34 @@ def log_out_button():
)
time.sleep(2)
st.stop()


def sso_redirect(provider: str):
auth_uri = getenv("MAGICALAUTH_SERVER")
if "code" in st.query_params:
if (
st.query_params["code"] != ""
and st.query_params["code"] is not None
and st.query_params["code"] != "None"
):
st.session_state["code"] = st.query_params["code"]
if "code" in st.session_state:
code = st.session_state["code"]
if code != "" and code is not None and code != "None":
referrer = f"{getenv('MAGIC_LINK_URL')}/{provider}"
response = requests.post(
f"{auth_uri}/v1/oauth2/{provider}",
json={"code": code, "referrer": referrer},
)
if response.status_code == 200:
data = response.json()
if "detail" in data:
new_uri = data["detail"]
st.markdown(
f'<meta http-equiv="refresh" content="0;URL={new_uri}">',
unsafe_allow_html=True,
)
st.stop()
else:
st.error(data)
st.stop()
32 changes: 2 additions & 30 deletions pages/github.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,3 @@
import streamlit as st
import requests
from Globals import getenv
from components.Auth import sso_redirect

auth_uri = getenv("MAGICALAUTH_SERVER")
if "code" in st.query_params:
if (
st.query_params["code"] != ""
and st.query_params["code"] is not None
and st.query_params["code"] != "None"
):
st.session_state["code"] = st.query_params["code"]
if "code" in st.session_state:
code = st.session_state["code"]
if code != "" and code is not None and code != "None":
response = requests.post(
f"{auth_uri}/v1/oauth2/github",
json={"code": code, "referrer": getenv("MAGIC_LINK_URL")},
)
if response.status_code == 200:
data = response.json()
if "detail" in data:
new_uri = data["detail"]
st.markdown(
f'<meta http-equiv="refresh" content="0;URL={new_uri}">',
unsafe_allow_html=True,
)
st.stop()
else:
st.error(data)
st.stop()
sso_redirect(provider="github")
32 changes: 2 additions & 30 deletions pages/google.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,3 @@
import streamlit as st
import requests
from Globals import getenv
from components.Auth import sso_redirect

auth_uri = getenv("MAGICALAUTH_SERVER")
if "code" in st.query_params:
if (
st.query_params["code"] != ""
and st.query_params["code"] is not None
and st.query_params["code"] != "None"
):
st.session_state["code"] = st.query_params["code"]
if "code" in st.session_state:
code = st.session_state["code"]
if code != "" and code is not None and code != "None":
response = requests.post(
f"{auth_uri}/v1/oauth2/google",
json={"code": code, "referrer": getenv("MAGIC_LINK_URL")},
)
if response.status_code == 200:
data = response.json()
if "detail" in data:
new_uri = data["detail"]
st.markdown(
f'<meta http-equiv="refresh" content="0;URL={new_uri}">',
unsafe_allow_html=True,
)
st.stop()
else:
st.error(data)
st.stop()
sso_redirect(provider="google")
32 changes: 2 additions & 30 deletions pages/microsoft.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,3 @@
import streamlit as st
import requests
from Globals import getenv
from components.Auth import sso_redirect

auth_uri = getenv("MAGICALAUTH_SERVER")
if "code" in st.query_params:
if (
st.query_params["code"] != ""
and st.query_params["code"] is not None
and st.query_params["code"] != "None"
):
st.session_state["code"] = st.query_params["code"]
if "code" in st.session_state:
code = st.session_state["code"]
if code != "" and code is not None and code != "None":
response = requests.post(
f"{auth_uri}/v1/oauth2/microsoft",
json={"code": code, "referrer": getenv("MAGIC_LINK_URL")},
)
if response.status_code == 200:
data = response.json()
if "detail" in data:
new_uri = data["detail"]
st.markdown(
f'<meta http-equiv="refresh" content="0;URL={new_uri}">',
unsafe_allow_html=True,
)
st.stop()
else:
st.error(data)
st.stop()
sso_redirect(provider="microsoft")

0 comments on commit b9e38ee

Please sign in to comment.