File size: 1,845 Bytes
99c4f8c
 
 
 
 
 
 
bd3b857
99c4f8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bd3b857
99c4f8c
 
 
 
3975e9b
99c4f8c
 
 
bd3b857
99c4f8c
bd3b857
99c4f8c
 
 
 
 
 
bd3b857
99c4f8c
 
 
bd3b857
 
99c4f8c
 
 
 
 
 
 
bd3b857
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
"""Script to get a Strava refresh token through OAuth flow."""

import asyncio
import logging
import os
import sys

from strava_mcp.oauth_server import get_refresh_token_from_oauth

# Configure logging
logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)
logger = logging.getLogger(__name__)


async def main():
    """Get a Strava refresh token."""
    # Check if client_id and client_secret are provided as env vars
    client_id = os.environ.get("STRAVA_CLIENT_ID")
    client_secret = os.environ.get("STRAVA_CLIENT_SECRET")

    # If not provided as env vars, check command line args
    if not client_id or not client_secret:
        if len(sys.argv) != 3:
            print("Usage: python get_token.py <client_id> <client_secret>")
            print("Or set STRAVA_CLIENT_ID and STRAVA_CLIENT_SECRET environment variables")
            sys.exit(1)
        client_id = sys.argv[1]
        client_secret = sys.argv[2]

    print("\nStarting Strava OAuth flow to get a refresh token...")

    try:
        token = await get_refresh_token_from_oauth(client_id, client_secret)
        print("\n=================================================================")
        print("SUCCESS! Add this to your environment variables:")
        print(f"export STRAVA_REFRESH_TOKEN={token}")
        print("=================================================================\n")

        # Also write to a file for easy access
        with open("strava_token.txt", "w") as f:
            f.write(f"STRAVA_REFRESH_TOKEN={token}\n")
        print("Token also saved to strava_token.txt\n")

    except Exception as e:
        logger.exception("Error getting refresh token")
        print(f"Error: {e}")
        sys.exit(1)


if __name__ == "__main__":
    asyncio.run(main())