Youssefk commited on
Commit
77d998d
·
1 Parent(s): fb73ea9

Upload 6 files

Browse files
Files changed (6) hide show
  1. .env_dummy +12 -0
  2. Makefile +16 -0
  3. README.md +69 -12
  4. app.py +33 -0
  5. requirements.txt +5 -0
  6. setup.py +19 -0
.env_dummy ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ CLIENT_ID = "537582539411-30v3dcg5hila3d6gaihn9ld3ue4tq4d4.apps.googleusercontent.com"
2
+ CLIENT_SECRET = "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"
3
+ REDIRECT_URI = "http://localhost:8501"
4
+ host = "host"
5
+ port = port_number
6
+ database = "database_name"
7
+ user = "root"
8
+ password = "your_pwd"
9
+ azure_event_key = "xxxxxxx"
10
+ azure_event_endpoint = "xxxxxxxxx"
11
+ azure_servicebus_conection_str = "XXXXX"
12
+ azure_servicebus_queue_name = "XXXXXX"
Makefile ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ VENV = .venv
2
+ PYTHON = $(VENV)/bin/python3
3
+ PIP = $(VENV)/bin/pip
4
+ STREAMLIT = $(VENV)/bin/streamlit
5
+ run: $(VENV)/bin/activate
6
+ $(STREAMLIT) run app.py
7
+
8
+
9
+ $(VENV)/bin/activate: requirements.txt
10
+ python3 -m venv $(VENV)
11
+ $(PIP) install -r requirements.txt
12
+
13
+
14
+ clean:
15
+ rm -rf __pycache__
16
+ rm -rf $(VENV)
README.md CHANGED
@@ -1,12 +1,69 @@
1
- ---
2
- title: G Auth
3
- emoji: 🦀
4
- colorFrom: pink
5
- colorTo: gray
6
- sdk: streamlit
7
- sdk_version: 1.19.0
8
- app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # streamlit-google-oauth
2
+ An example [Streamlit](https://streamlit.io/) application that incorporates Google OAuth 2.0
3
+
4
+ ## PIP
5
+ ```bash
6
+ pip install git+https://github.com/hunkim/streamlit-google-oauth
7
+ ```
8
+
9
+ ## Setup Google OAuth client ID
10
+ <img width="1434" alt="image" src="https://user-images.githubusercontent.com/901975/170391098-c3a79b40-283a-4f78-a318-c4603bb18bb9.png">
11
+
12
+
13
+ ### Make sure people api is enabled
14
+ <img width="1070" alt="image" src="https://user-images.githubusercontent.com/901975/170388473-4664ce58-6a06-4237-9fbe-d88787f41c22.png">
15
+
16
+
17
+ ## Put client id, etc. in env
18
+ Put in the .env file
19
+ ```bash
20
+ ~/streamlit-google-oauth$ cat .env
21
+ GOOGLE_CLIENT_ID=767025784452-fscnojvddiek...
22
+ GOOGLE_CLIENT_SECRET=GOCSPX-KE4_...
23
+ GOOGLE_REDIRECT_URI=http://localhost:8080
24
+ ```
25
+
26
+ or
27
+ ```bash
28
+ export GOOGLE_CLIENT_ID="xxx"
29
+ export GOOGLE_CLIENT_SECRET="yyy"
30
+ export GOOGLE_REDIRECT_URI="http://localhost:8080"
31
+ ```
32
+
33
+ ## Add login in your streamlit app
34
+ ```python
35
+ import streamlit as st
36
+ import os
37
+ from dotenv import load_dotenv
38
+ import streamlit_google_oauth as oauth
39
+
40
+ load_dotenv()
41
+ client_id = os.environ["GOOGLE_CLIENT_ID"]
42
+ client_secret = os.environ["GOOGLE_CLIENT_SECRET"]
43
+ redirect_uri = os.environ["GOOGLE_REDIRECT_URI"]
44
+
45
+
46
+ if __name__ == "__main__":
47
+ login_info = oauth.login(
48
+ client_id=client_id,
49
+ client_secret=client_secret,
50
+ redirect_uri=redirect_uri,
51
+ login_button_text="Continue with Google",
52
+ logout_button_text="Logout",
53
+ )
54
+ if login_info:
55
+ user_id, user_email = login_info
56
+ st.write(f"Welcome {user_email}")
57
+ else:
58
+ st.write("Please login")
59
+ ```
60
+
61
+ ## Run streamlit with google oauth
62
+ ```bash
63
+ streamlit run app.py --server.port 8080
64
+ ```
65
+ ## Quick demo screenshots
66
+ ![Quick demo](https://user-images.githubusercontent.com/901975/170390886-004e7243-7cac-4ace-91fc-ede46ad40c5f.png)
67
+
68
+
69
+
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ # from dotenv import load_dotenv
4
+ import streamlit_google_oauth as oauth
5
+
6
+ # load_dotenv()
7
+ client_id = "657069732284-mbcb1l7ra4pask18n2cc7a29123ldsm3.apps.googleusercontent.com"
8
+ client_secret = "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"
9
+ redirect_uri = "https://agiveon-ath.streamlit.app/?embed=True"
10
+
11
+
12
+ if __name__ == "__main__":
13
+ app_name = '''
14
+ Streamlit Google Authentication Demo
15
+ '''
16
+ app_desc = '''
17
+ A streamlit application that authenticates users by <strong>Google Oauth</strong>.
18
+ The user must have a google account to log in into the application.
19
+ '''
20
+ login_info = oauth.login(
21
+ client_id=client_id,
22
+ client_secret=client_secret,
23
+ redirect_uri=redirect_uri,
24
+ app_name=app_name,
25
+ app_desc=app_desc,
26
+ logout_button_text="Logout",
27
+ )
28
+ if login_info:
29
+ user_id, user_email = login_info
30
+ st.write(f"Welcome {user_email}")
31
+
32
+ # streamlit run app.py --server.port 8080
33
+
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ protobuf<=3.20
2
+ streamlit
3
+ httpx-oauth
4
+ python-dotenv
5
+ typing_extensions
setup.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from setuptools import setup
2
+
3
+ # from streamlit_google_oauth import __version__
4
+
5
+ setup(
6
+ name="streamlit_google_oauth",
7
+ version="0.1",
8
+ url="https://github.com/hunkim/streamlit-google-oauth",
9
+ author="Sung Kim",
10
+ author_email="hunkim@gmail.com",
11
+ py_modules=["streamlit_google_oauth"],
12
+ packages=["streamlit_google_oauth"],
13
+ install_requires=[
14
+ "protobuf<=3.20",
15
+ "streamlit",
16
+ "httpx-oauth",
17
+ "typing-extensions",
18
+ ],
19
+ )