-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgoogle_auth_decorator.py
More file actions
40 lines (30 loc) · 1.02 KB
/
Copy pathgoogle_auth_decorator.py
File metadata and controls
40 lines (30 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import functools
import streamlit as st
from google_oauth_support import get_google_oauth
import webbrowser
def logout():
"""
logout loads the submit button for logout
"""
with st.form(key='logout', clear_on_submit=True):
submit_button = st.form_submit_button(label='logout')
if submit_button:
# await client.revoke_token("TOKEN")
# client.revoke_token(token) isnt deleting token from session
st.session_state.token = None
st.session_state.token = None
webbrowser.open("http://localhost:8501/")
def google_auth_required(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
# google oauth
status, google_auth_response = get_google_oauth()
if status:
# Run the decorated function
result = func(*args, **kwargs)
logout()
return result
else:
# Display the Google sign-in button
st.write(google_auth_response, unsafe_allow_html=True)
return wrapper