if st.button('Authorize Strava Access'):
# Construct the authorization url
auth_url = f"https://www.strava.com/oauth/authorize?client_id={''}&response_type=code&redirect_uri={'http://localhost/'}&scope={'activity:read_all'}&approval_prompt=force"
# Redirect the user to the authorization url
webbrowser.open_new_tab(auth_url)
authorization_code = st.text_input('Enter the authorization code:')
Are there any cleaner solutions with Streamlit to connect this API? without the manual redirect?
So you are correct in saying that Strava handles the authentication for a 3rd party app.
The issue that I am trying to navigate is the manual process that the user on streamlit would have to proceed with to ensure this authentication takes place.
Below
def app(df):
st.set_page_config(page_title='Home')
client_id = '' # your client_id goes here
client_secret = '' # your client_secret goes here
if st.button('Authorize Strava Access'):
# Construct the authorization url
auth_url = f"https://www.strava.com/oauth/authorize?client_id={client_id}&response_type=code&redirect_uri={'http://localhost/'}&scope={'activity:read_all'}&approval_prompt=force"
# Redirect the user to the authorization url
webbrowser.open_new_tab(auth_url)
authorization_code = st.text_input('Enter the authorization code:')
if authorization_code:
# Request access token
response = request_token(client_id, client_secret, authorization_code)
print(f"Response from request_token: {response}") # Debug print statement
# Check response status
access_token = response['access_token']
# Get the user's activity data
activity_data = get_all_activity_data(access_token)
# Convert the activity data to a dataframe
df = pd.DataFrame(activity_data)
The workflow at the moment is as follows -
Click st.button to redirect to auth_url
User logs in on strava url
User click authorise.
4.New url loaded with auth code in. User copies this auth code into st.text_input
This is inputted into another function (request_token)
Access token is returned and data is generated.
I want to take out the manual step4, is that possible with streamlit?
Hi!
i deployed my app on streamlit cloud; i want to give access to only user with specific ip addresses but my code is working in local environment but not worked in deployed environment. I dont what is the issue.
Thanks in advance!!
here is my code:
ALLOWED_IP_ADDRESSES = [“124.109.39.000”, “319.32.24.988”]
def get_user_ip():
try:
response = requests.get(“https://api64.ipify.org?format=json”)
if response.status_code == 200 and “ip” in response.json():
return response.json()[“ip”]
except requests.RequestException as e:
st.error(f"Error occurred while getting IP: {e}")
return "127.0.0.1"
def main():
st.title(“IP Address Detection”)
user_ip = get_user_ip()
st.write("Your IP address:", user_ip)
if user_ip not in ALLOWED_IP_ADDRESSES:
st.error("Access denied. Your IP address is not allowed.")
return
st.success("Access granted. You are allowed to access the app.")
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.