Add OIDC Authorization

This commit is contained in:
George 2024-10-04 12:10:31 -07:00
parent 4b49def86d
commit f6d2373f39
2 changed files with 29 additions and 15 deletions

View File

@ -30,7 +30,7 @@ from dash import Dash, html, dcc, callback, Output, Input, State, no_update
from waitress import serve from waitress import serve
from flask_caching import Cache from flask_caching import Cache
from dash.exceptions import PreventUpdate from dash.exceptions import PreventUpdate
import dash_auth from dash_auth import OIDCAuth
import yahoo_fin.stock_info as si import yahoo_fin.stock_info as si
import hashlib import hashlib
from dotenv import load_dotenv from dotenv import load_dotenv
@ -551,23 +551,33 @@ def intelligent_loop_plots(sym, stk_data):
return data, vol.to_frame('_VOL'), macd, rsi, plot_indicator return data, vol.to_frame('_VOL'), macd, rsi, plot_indicator
VALID_USERNAME_PASSWORD_PAIRS = { # VALID_USERNAME_PASSWORD_PAIRS = {
'ce16559af2caf7bb54bebd57a1602e29ada331b3356004265abeab0e568278cc': # 'ce16559af2caf7bb54bebd57a1602e29ada331b3356004265abeab0e568278cc':
'b4db36eb3f887ca0bc15de7feb0b41a9589b65dbd5325aedf1c76b3ee63b8871' # 'b4db36eb3f887ca0bc15de7feb0b41a9589b65dbd5325aedf1c76b3ee63b8871'
} # }
def user_login(username, password): # def user_login(username, password):
if VALID_USERNAME_PASSWORD_PAIRS.get(hash_password(username)) == hash_password(password): # if VALID_USERNAME_PASSWORD_PAIRS.get(hash_password(username)) == hash_password(password):
return True # return True
return False # return False
# Initialize the app # Initialize the app
app = Dash() app = Dash(__name__)
dash_auth.BasicAuth(
app, # dash_auth.BasicAuth(
# VALID_USERNAME_PASSWORD_PAIRS, # app,
auth_func=user_login, # # VALID_USERNAME_PASSWORD_PAIRS,
secret_key="MK8dyS6PyDDuEuzrmqa7dJTJZ7eH2Jkh", # auth_func=user_login,
# secret_key="MK8dyS6PyDDuEuzrmqa7dJTJZ7eH2Jkh",
# )
auth = OIDCAuth(app, secret_key=os.environ['SECRET_KEY'])
auth.register_provider(
"stock",
token_endpoint_auth_method="client_secret_post",
client_id=os.environ['APP_ID'],
client_secret=os.environ['APP_SECRET'],
server_metadata_url=os.environ['SERVER_URL'],
) )
watchlist = get_watchlist() watchlist = get_watchlist()

View File

@ -1,12 +1,15 @@
appdirs==1.4.4 appdirs==1.4.4
Authlib==1.3.2
beautifulsoup4==4.12.3 beautifulsoup4==4.12.3
blinker==1.8.2 blinker==1.8.2
bs4==0.0.2 bs4==0.0.2
cachelib==0.9.0 cachelib==0.9.0
certifi==2024.8.30 certifi==2024.8.30
cffi==1.17.1
charset-normalizer==3.3.2 charset-normalizer==3.3.2
click==8.1.7 click==8.1.7
colorama==0.4.6 colorama==0.4.6
cryptography==43.0.1
cssselect==1.2.0 cssselect==1.2.0
dash==2.18.1 dash==2.18.1
dash-core-components==2.0.0 dash-core-components==2.0.0
@ -31,6 +34,7 @@ pandas==2.2.3
parse==1.20.2 parse==1.20.2
plotly==5.24.1 plotly==5.24.1
psycopg2==2.9.9 psycopg2==2.9.9
pycparser==2.22
pyee==11.1.1 pyee==11.1.1
pyppeteer==2.0.0 pyppeteer==2.0.0
pyquery==2.0.1 pyquery==2.0.1