fadliaulawi commited on
Commit
f72e2f5
·
1 Parent(s): 729049b
Files changed (3) hide show
  1. app.py +6 -0
  2. auth_middleware.py +34 -0
  3. requirements.txt +23 -1
app.py CHANGED
@@ -12,6 +12,8 @@ from streamlit_pdf_viewer import pdf_viewer
12
  from utils import blob_service_client, upload_to_azure, download_from_azure, delete_from_azure
13
  from streamlit_msal import Msal
14
 
 
 
15
  load_dotenv()
16
  st.set_page_config(layout="wide")
17
 
@@ -182,3 +184,7 @@ else:
182
  file_name=f"{lang_name}-translated-files.zip",
183
  mime="application/zip"
184
  )
 
 
 
 
 
12
  from utils import blob_service_client, upload_to_azure, download_from_azure, delete_from_azure
13
  from streamlit_msal import Msal
14
 
15
+ from auth_middleware import app as auth_app
16
+
17
  load_dotenv()
18
  st.set_page_config(layout="wide")
19
 
 
184
  file_name=f"{lang_name}-translated-files.zip",
185
  mime="application/zip"
186
  )
187
+
188
+ # Proxy Streamlit through Flask
189
+ def run():
190
+ os.system("streamlit run streamlit_app.py --server.port=8501 --server.address=0.0.0.0")
auth_middleware.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, redirect, session
2
+ from authlib.integrations.flask_client import OAuth
3
+ import os
4
+
5
+ # Flask app setup
6
+ app = Flask(__name__)
7
+ app.secret_key = os.getenv("FLASK_SECRET_KEY")
8
+
9
+ # OAuth setup
10
+ oauth = OAuth(app)
11
+ azure = oauth.register(
12
+ name='azure',
13
+ client_id=os.getenv("AZURE_CLIENT_ID"),
14
+ client_secret=os.getenv("AZURE_CLIENT_SECRET"),
15
+ server_metadata_url=f"https://login.microsoftonline.com/{os.getenv('AZURE_TENANT_ID')}/v2.0/.well-known/openid-configuration",
16
+ client_kwargs={"scope": "openid email profile"},
17
+ )
18
+
19
+ @app.route("/login")
20
+ def login():
21
+ redirect_uri = os.getenv("REDIRECT_URI", "http://localhost:8501")
22
+ return azure.authorize_redirect(redirect_uri)
23
+
24
+ @app.route("/callback")
25
+ def callback():
26
+ token = azure.authorize_access_token()
27
+ user = azure.parse_id_token(token)
28
+ # You can save user info or session here
29
+ return redirect("/")
30
+
31
+ @app.before_request
32
+ def auth_middleware():
33
+ if request.endpoint not in ("login", "callback") and "user" not in session:
34
+ return redirect("/login")
requirements.txt CHANGED
@@ -1,4 +1,11 @@
 
 
 
1
  altair==5.5.0
 
 
 
 
2
  azure-ai-translation-document==1.1.0
3
  azure-core==1.32.0
4
  azure-storage-blob==12.24.0
@@ -10,12 +17,16 @@ chardet==5.2.0
10
  charset-normalizer==3.4.0
11
  click==8.1.7
12
  cobble==0.1.4
13
- cryptography==44.0.0
14
  docx2pdf==0.1.8
 
 
 
15
  gitdb==4.0.11
16
  GitPython==3.1.43
17
  idna==3.10
18
  isodate==0.7.2
 
19
  Jinja2==3.1.4
20
  jsonschema==4.23.0
21
  jsonschema-specifications==2024.10.1
@@ -24,30 +35,39 @@ mammoth==1.8.0
24
  markdown-it-py==3.0.0
25
  MarkupSafe==3.0.2
26
  mdurl==0.1.2
 
27
  narwhals==1.16.0
28
  numpy==2.2.0
29
  packaging==24.2
30
  pandas==2.2.3
31
  pdfkit==1.0.0
 
32
  pillow==11.0.0
 
33
  protobuf==5.29.1
34
  pyarrow==18.1.0
 
35
  pycparser==2.22
36
  pydeck==0.9.1
37
  Pygments==2.18.0
 
38
  pypandoc==1.14
39
  python-dateutil==2.9.0.post0
40
  python-docx==1.1.2
41
  python-dotenv==1.0.1
 
42
  pytz==2024.2
43
  referencing==0.35.1
44
  reportlab==4.2.5
45
  requests==2.32.3
46
  rich==13.9.4
47
  rpds-py==0.22.3
 
48
  six==1.17.0
49
  smmap==5.0.1
50
  streamlit==1.40.2
 
 
51
  streamlit-msal==0.2.0
52
  streamlit-pdf-viewer==0.0.19
53
  tenacity==9.0.0
@@ -57,3 +77,5 @@ tqdm==4.67.1
57
  typing_extensions==4.12.2
58
  tzdata==2024.2
59
  urllib3==2.2.3
 
 
 
1
+ aiohappyeyeballs==2.4.4
2
+ aiohttp==3.11.10
3
+ aiosignal==1.3.1
4
  altair==5.5.0
5
+ appscript==1.3.0
6
+ attrs==24.2.0
7
+ auth0-python==4.7.2
8
+ Authlib==1.3.2
9
  azure-ai-translation-document==1.1.0
10
  azure-core==1.32.0
11
  azure-storage-blob==12.24.0
 
17
  charset-normalizer==3.4.0
18
  click==8.1.7
19
  cobble==0.1.4
20
+ cryptography==43.0.3
21
  docx2pdf==0.1.8
22
+ ecdsa==0.19.0
23
+ Flask==3.1.0
24
+ frozenlist==1.5.0
25
  gitdb==4.0.11
26
  GitPython==3.1.43
27
  idna==3.10
28
  isodate==0.7.2
29
+ itsdangerous==2.2.0
30
  Jinja2==3.1.4
31
  jsonschema==4.23.0
32
  jsonschema-specifications==2024.10.1
 
35
  markdown-it-py==3.0.0
36
  MarkupSafe==3.0.2
37
  mdurl==0.1.2
38
+ multidict==6.1.0
39
  narwhals==1.16.0
40
  numpy==2.2.0
41
  packaging==24.2
42
  pandas==2.2.3
43
  pdfkit==1.0.0
44
+ pdflatex==0.1.3
45
  pillow==11.0.0
46
+ propcache==0.2.1
47
  protobuf==5.29.1
48
  pyarrow==18.1.0
49
+ pyasn1==0.6.1
50
  pycparser==2.22
51
  pydeck==0.9.1
52
  Pygments==2.18.0
53
+ PyJWT==2.10.1
54
  pypandoc==1.14
55
  python-dateutil==2.9.0.post0
56
  python-docx==1.1.2
57
  python-dotenv==1.0.1
58
+ python-jose==3.3.0
59
  pytz==2024.2
60
  referencing==0.35.1
61
  reportlab==4.2.5
62
  requests==2.32.3
63
  rich==13.9.4
64
  rpds-py==0.22.3
65
+ rsa==4.9
66
  six==1.17.0
67
  smmap==5.0.1
68
  streamlit==1.40.2
69
+ streamlit-auth0==1.0.5
70
+ streamlit-auth0-component==0.1.5
71
  streamlit-msal==0.2.0
72
  streamlit-pdf-viewer==0.0.19
73
  tenacity==9.0.0
 
77
  typing_extensions==4.12.2
78
  tzdata==2024.2
79
  urllib3==2.2.3
80
+ Werkzeug==3.1.3
81
+ yarl==1.18.3