Spaces:
Running
Running
JonSolow
commited on
Add login with streamlit_oauth (#1)
Browse files* Add fork of yahoo_fantasy_api to reqs
* Add secrets.toml to gitignore
* Add login using streamlit_oauth
- .gitignore +3 -0
- dev-requirements.txt +27 -2
- pyproject.toml +7 -0
- requirements.txt +27 -2
- src/Home.py +2 -1
- src/login_component.py +45 -0
- src/pages/1_Keepers.py +2 -0
- src/pages/2_Rules.py +2 -0
.gitignore
CHANGED
|
@@ -158,3 +158,6 @@ cython_debug/
|
|
| 158 |
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
| 159 |
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
| 160 |
#.idea/
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
| 159 |
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
| 160 |
#.idea/
|
| 161 |
+
|
| 162 |
+
# Streamlit
|
| 163 |
+
secrets.toml
|
dev-requirements.txt
CHANGED
|
@@ -6,6 +6,8 @@
|
|
| 6 |
#
|
| 7 |
altair==5.0.1
|
| 8 |
# via streamlit
|
|
|
|
|
|
|
| 9 |
attrs==23.1.0
|
| 10 |
# via
|
| 11 |
# jsonschema
|
|
@@ -17,7 +19,10 @@ blinker==1.6.2
|
|
| 17 |
cachetools==5.3.1
|
| 18 |
# via streamlit
|
| 19 |
certifi==2023.7.22
|
| 20 |
-
# via
|
|
|
|
|
|
|
|
|
|
| 21 |
charset-normalizer==3.2.0
|
| 22 |
# via requests
|
| 23 |
click==8.1.6
|
|
@@ -28,8 +33,19 @@ gitdb==4.0.10
|
|
| 28 |
# via gitpython
|
| 29 |
gitpython==3.1.32
|
| 30 |
# via streamlit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
idna==3.4
|
| 32 |
-
# via
|
|
|
|
|
|
|
|
|
|
| 33 |
importlib-metadata==6.8.0
|
| 34 |
# via streamlit
|
| 35 |
iniconfig==2.0.0
|
|
@@ -121,7 +137,16 @@ six==1.16.0
|
|
| 121 |
# via python-dateutil
|
| 122 |
smmap==5.0.0
|
| 123 |
# via gitdb
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
streamlit==1.25.0
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
# via YFDashboard (pyproject.toml)
|
| 126 |
tenacity==8.2.3
|
| 127 |
# via streamlit
|
|
|
|
| 6 |
#
|
| 7 |
altair==5.0.1
|
| 8 |
# via streamlit
|
| 9 |
+
anyio==3.7.1
|
| 10 |
+
# via httpcore
|
| 11 |
attrs==23.1.0
|
| 12 |
# via
|
| 13 |
# jsonschema
|
|
|
|
| 19 |
cachetools==5.3.1
|
| 20 |
# via streamlit
|
| 21 |
certifi==2023.7.22
|
| 22 |
+
# via
|
| 23 |
+
# httpcore
|
| 24 |
+
# httpx
|
| 25 |
+
# requests
|
| 26 |
charset-normalizer==3.2.0
|
| 27 |
# via requests
|
| 28 |
click==8.1.6
|
|
|
|
| 33 |
# via gitpython
|
| 34 |
gitpython==3.1.32
|
| 35 |
# via streamlit
|
| 36 |
+
h11==0.14.0
|
| 37 |
+
# via httpcore
|
| 38 |
+
httpcore==0.17.3
|
| 39 |
+
# via httpx
|
| 40 |
+
httpx==0.24.1
|
| 41 |
+
# via httpx-oauth
|
| 42 |
+
httpx-oauth==0.13.0
|
| 43 |
+
# via streamlit-oauth
|
| 44 |
idna==3.4
|
| 45 |
+
# via
|
| 46 |
+
# anyio
|
| 47 |
+
# httpx
|
| 48 |
+
# requests
|
| 49 |
importlib-metadata==6.8.0
|
| 50 |
# via streamlit
|
| 51 |
iniconfig==2.0.0
|
|
|
|
| 137 |
# via python-dateutil
|
| 138 |
smmap==5.0.0
|
| 139 |
# via gitdb
|
| 140 |
+
sniffio==1.3.0
|
| 141 |
+
# via
|
| 142 |
+
# anyio
|
| 143 |
+
# httpcore
|
| 144 |
+
# httpx
|
| 145 |
streamlit==1.25.0
|
| 146 |
+
# via
|
| 147 |
+
# YFDashboard (pyproject.toml)
|
| 148 |
+
# streamlit-oauth
|
| 149 |
+
streamlit-oauth==0.0.1
|
| 150 |
# via YFDashboard (pyproject.toml)
|
| 151 |
tenacity==8.2.3
|
| 152 |
# via streamlit
|
pyproject.toml
CHANGED
|
@@ -9,6 +9,7 @@ dependencies = [
|
|
| 9 |
"streamlit",
|
| 10 |
"numpy",
|
| 11 |
"pandas",
|
|
|
|
| 12 |
]
|
| 13 |
|
| 14 |
[project.optional-dependencies]
|
|
@@ -30,3 +31,9 @@ src = ["src"]
|
|
| 30 |
|
| 31 |
[tool.mypy]
|
| 32 |
python_version = "3.11"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
"streamlit",
|
| 10 |
"numpy",
|
| 11 |
"pandas",
|
| 12 |
+
"streamlit-oauth",
|
| 13 |
]
|
| 14 |
|
| 15 |
[project.optional-dependencies]
|
|
|
|
| 31 |
|
| 32 |
[tool.mypy]
|
| 33 |
python_version = "3.11"
|
| 34 |
+
|
| 35 |
+
[[tool.mypy.overrides]]
|
| 36 |
+
module = [
|
| 37 |
+
'streamlit_oauth'
|
| 38 |
+
]
|
| 39 |
+
ignore_missing_imports = true
|
requirements.txt
CHANGED
|
@@ -6,6 +6,8 @@
|
|
| 6 |
#
|
| 7 |
altair==5.0.1
|
| 8 |
# via streamlit
|
|
|
|
|
|
|
| 9 |
attrs==23.1.0
|
| 10 |
# via
|
| 11 |
# jsonschema
|
|
@@ -15,7 +17,10 @@ blinker==1.6.2
|
|
| 15 |
cachetools==5.3.1
|
| 16 |
# via streamlit
|
| 17 |
certifi==2023.7.22
|
| 18 |
-
# via
|
|
|
|
|
|
|
|
|
|
| 19 |
charset-normalizer==3.2.0
|
| 20 |
# via requests
|
| 21 |
click==8.1.6
|
|
@@ -24,8 +29,19 @@ gitdb==4.0.10
|
|
| 24 |
# via gitpython
|
| 25 |
gitpython==3.1.32
|
| 26 |
# via streamlit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
idna==3.4
|
| 28 |
-
# via
|
|
|
|
|
|
|
|
|
|
| 29 |
importlib-metadata==6.8.0
|
| 30 |
# via streamlit
|
| 31 |
jinja2==3.1.2
|
|
@@ -93,7 +109,16 @@ six==1.16.0
|
|
| 93 |
# via python-dateutil
|
| 94 |
smmap==5.0.0
|
| 95 |
# via gitdb
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
streamlit==1.25.0
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
# via YFDashboard (pyproject.toml)
|
| 98 |
tenacity==8.2.3
|
| 99 |
# via streamlit
|
|
|
|
| 6 |
#
|
| 7 |
altair==5.0.1
|
| 8 |
# via streamlit
|
| 9 |
+
anyio==3.7.1
|
| 10 |
+
# via httpcore
|
| 11 |
attrs==23.1.0
|
| 12 |
# via
|
| 13 |
# jsonschema
|
|
|
|
| 17 |
cachetools==5.3.1
|
| 18 |
# via streamlit
|
| 19 |
certifi==2023.7.22
|
| 20 |
+
# via
|
| 21 |
+
# httpcore
|
| 22 |
+
# httpx
|
| 23 |
+
# requests
|
| 24 |
charset-normalizer==3.2.0
|
| 25 |
# via requests
|
| 26 |
click==8.1.6
|
|
|
|
| 29 |
# via gitpython
|
| 30 |
gitpython==3.1.32
|
| 31 |
# via streamlit
|
| 32 |
+
h11==0.14.0
|
| 33 |
+
# via httpcore
|
| 34 |
+
httpcore==0.17.3
|
| 35 |
+
# via httpx
|
| 36 |
+
httpx==0.24.1
|
| 37 |
+
# via httpx-oauth
|
| 38 |
+
httpx-oauth==0.13.0
|
| 39 |
+
# via streamlit-oauth
|
| 40 |
idna==3.4
|
| 41 |
+
# via
|
| 42 |
+
# anyio
|
| 43 |
+
# httpx
|
| 44 |
+
# requests
|
| 45 |
importlib-metadata==6.8.0
|
| 46 |
# via streamlit
|
| 47 |
jinja2==3.1.2
|
|
|
|
| 109 |
# via python-dateutil
|
| 110 |
smmap==5.0.0
|
| 111 |
# via gitdb
|
| 112 |
+
sniffio==1.3.0
|
| 113 |
+
# via
|
| 114 |
+
# anyio
|
| 115 |
+
# httpcore
|
| 116 |
+
# httpx
|
| 117 |
streamlit==1.25.0
|
| 118 |
+
# via
|
| 119 |
+
# YFDashboard (pyproject.toml)
|
| 120 |
+
# streamlit-oauth
|
| 121 |
+
streamlit-oauth==0.0.1
|
| 122 |
# via YFDashboard (pyproject.toml)
|
| 123 |
tenacity==8.2.3
|
| 124 |
# via streamlit
|
src/Home.py
CHANGED
|
@@ -1,12 +1,13 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
from config import DEFAULT_ICON, LEAGUE_NAME
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
def get_app():
|
| 7 |
keeper_title = f"{LEAGUE_NAME}"
|
| 8 |
st.set_page_config(page_title=keeper_title, page_icon=DEFAULT_ICON)
|
| 9 |
-
|
| 10 |
st.markdown(
|
| 11 |
f"""
|
| 12 |
Welcome {LEAGUE_NAME}!
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
from config import DEFAULT_ICON, LEAGUE_NAME
|
| 4 |
+
from login_component import get_authorization_button
|
| 5 |
|
| 6 |
|
| 7 |
def get_app():
|
| 8 |
keeper_title = f"{LEAGUE_NAME}"
|
| 9 |
st.set_page_config(page_title=keeper_title, page_icon=DEFAULT_ICON)
|
| 10 |
+
get_authorization_button()
|
| 11 |
st.markdown(
|
| 12 |
f"""
|
| 13 |
Welcome {LEAGUE_NAME}!
|
src/login_component.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
from streamlit_oauth import OAuth2Component
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
# # Load environment variables from .env file
|
| 7 |
+
# from dotenv import load_dotenv
|
| 8 |
+
# load_dotenv()
|
| 9 |
+
|
| 10 |
+
# Set environment variables
|
| 11 |
+
AUTHORIZE_URL = os.environ.get("AUTHORIZE_URL")
|
| 12 |
+
TOKEN_URL = os.environ.get("TOKEN_URL")
|
| 13 |
+
REFRESH_TOKEN_URL = os.environ.get("REFRESH_TOKEN_URL")
|
| 14 |
+
REVOKE_TOKEN_URL = os.environ.get("REVOKE_TOKEN_URL")
|
| 15 |
+
CLIENT_ID = os.environ.get("CLIENT_ID")
|
| 16 |
+
CLIENT_SECRET = os.environ.get("CLIENT_SECRET")
|
| 17 |
+
REDIRECT_URI = os.environ.get("REDIRECT_URI")
|
| 18 |
+
SCOPE = os.environ.get("SCOPE")
|
| 19 |
+
|
| 20 |
+
# Create OAuth2Component instance
|
| 21 |
+
oauth2 = OAuth2Component(CLIENT_ID, CLIENT_SECRET, AUTHORIZE_URL, TOKEN_URL, REFRESH_TOKEN_URL, REVOKE_TOKEN_URL)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def get_authorization_button():
|
| 25 |
+
# Check if token exists in session state
|
| 26 |
+
if "token" not in st.session_state:
|
| 27 |
+
# If not, show authorize button
|
| 28 |
+
result = oauth2.authorize_button("Login", REDIRECT_URI, SCOPE)
|
| 29 |
+
if result and "token" in result:
|
| 30 |
+
# If authorization successful, save token in session state
|
| 31 |
+
st.session_state.token = result.get("token")
|
| 32 |
+
st.experimental_rerun()
|
| 33 |
+
else:
|
| 34 |
+
# # If token exists in session state, allow logout
|
| 35 |
+
st.session_state["token"]
|
| 36 |
+
if st.button("Logout"):
|
| 37 |
+
del st.session_state.token
|
| 38 |
+
st.experimental_rerun()
|
| 39 |
+
# # If token exists in session state, show the token
|
| 40 |
+
# token = st.session_state["token"]
|
| 41 |
+
# if st.button("Refresh Token"):
|
| 42 |
+
# # If refresh token button is clicked, refresh the token
|
| 43 |
+
# token = oauth2.refresh_token(token)
|
| 44 |
+
# st.session_state.token = token
|
| 45 |
+
# st.experimental_rerun()
|
src/pages/1_Keepers.py
CHANGED
|
@@ -3,6 +3,7 @@ import pandas as pd
|
|
| 3 |
import streamlit as st
|
| 4 |
|
| 5 |
from config import DEFAULT_ICON, LEAGUE_NAME, LEAGUE_NUMBER_TEAMS
|
|
|
|
| 6 |
from streamlit_filter import filter_dataframe
|
| 7 |
|
| 8 |
|
|
@@ -135,6 +136,7 @@ def filtered_keeper_dataframe(data: pd.DataFrame, teams_list: list[str]):
|
|
| 135 |
def get_keeper_app():
|
| 136 |
keeper_title = f"{LEAGUE_NAME} Keeper Options"
|
| 137 |
st.set_page_config(page_title=keeper_title, page_icon=DEFAULT_ICON, layout="wide")
|
|
|
|
| 138 |
st.title(keeper_title)
|
| 139 |
data, teams_list = load_data()
|
| 140 |
|
|
|
|
| 3 |
import streamlit as st
|
| 4 |
|
| 5 |
from config import DEFAULT_ICON, LEAGUE_NAME, LEAGUE_NUMBER_TEAMS
|
| 6 |
+
from login_component import get_authorization_button
|
| 7 |
from streamlit_filter import filter_dataframe
|
| 8 |
|
| 9 |
|
|
|
|
| 136 |
def get_keeper_app():
|
| 137 |
keeper_title = f"{LEAGUE_NAME} Keeper Options"
|
| 138 |
st.set_page_config(page_title=keeper_title, page_icon=DEFAULT_ICON, layout="wide")
|
| 139 |
+
get_authorization_button()
|
| 140 |
st.title(keeper_title)
|
| 141 |
data, teams_list = load_data()
|
| 142 |
|
src/pages/2_Rules.py
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
from config import DEFAULT_ICON, LEAGUE_NAME
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
page_title = f"{LEAGUE_NAME} Keeper Rules"
|
| 7 |
st.set_page_config(page_title=page_title, page_icon=DEFAULT_ICON)
|
|
|
|
| 8 |
st.title(page_title)
|
| 9 |
st.markdown(
|
| 10 |
"""
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
from config import DEFAULT_ICON, LEAGUE_NAME
|
| 4 |
+
from login_component import get_authorization_button
|
| 5 |
|
| 6 |
|
| 7 |
page_title = f"{LEAGUE_NAME} Keeper Rules"
|
| 8 |
st.set_page_config(page_title=page_title, page_icon=DEFAULT_ICON)
|
| 9 |
+
get_authorization_button()
|
| 10 |
st.title(page_title)
|
| 11 |
st.markdown(
|
| 12 |
"""
|