Authentication¶
Single-user mode¶
SweatStack supports three authentication methods in order of priority:
1. Browser-Based OAuth2 Authentication¶
This is the recommended authentication method for most users. It opens your default browser for the SweatStack authentication flow:
import sweatstack as ss
ss.login() # Opens your default browser for authentication
2. Direct API Key Authentication¶
Provide your API key directly when creating a client:
from sweatstack import Client
client = Client(api_key="your-api-key")
3. Environment Variable¶
Set the SWEATSTACK_API_KEY
environment variable:
export SWEATSTACK_API_KEY="your-api-key"
Then use the library without explicit authentication:
import sweatstack as ss
activities = ss.get_activities() # Uses SWEATSTACK_API_KEY
Authentication Priority:
1. Browser-based OAuth2 (ss.login()
)
2. Direct API key via Client
constructor
3. SWEATSTACK_API_KEY
environment variable
Application authentication¶
SweatStack offers application authentication that follows the OAuth2/OpenID Connect specification. This allows third-party applications to request authorization from users without exposing their credentials.
Check the .well-known
endpoints in the interactive API docs to get started: https://app.sweatstack.no/docs#/well-known.
User Switching¶
Quickly switch between users you have access to:
import sweatstack as ss
# Get all accessible users
users = ss.get_users()
# Switch to a specific user (for coaches/managers)
ss.switch_user(users[0])
# ...or reate a delegated client for a specific user
athlete_client = ss.delegated_client(users[0])
athlete_activities = athlete_client.get_activities()
# Switch back to your principal user (i.e. the logged in user)
ss.switch_back()