# Getting Refresh Token (When Credentials Are Already Set)
If you already have `STRAVA_CLIENT_ID` and `STRAVA_CLIENT_SECRET` configured (either in `.env` or as environment variables), follow these simplified steps to get your refresh token.
## Quick Overview
When credentials are already set, you only need to:
1. Get the authorization URL
2. Visit it and authorize
3. Copy the authorization code
4. Complete authentication
5. Restart the server
## Step 1: Verify Credentials Are Set
**Prompt:**
```
Check my Strava authentication status
```
**Expected Result:**
```json
{
"is_configured": false,
"has_client_id": true,
"has_client_secret": true,
"has_refresh_token": false,
"message": "Credentials found but refresh token missing. Complete authentication to get refresh token."
}
```
If you see `has_client_id: true` and `has_client_secret: true`, you're ready to proceed!
---
## Step 2: Get Authorization URL
**Prompt:**
```
Get the Strava authorization URL
```
**Tool:**
```python
get_auth_url()
```
**Expected Result:**
A URL like:
```
https://www.strava.com/oauth/authorize?client_id=YOUR_ID&redirect_uri=http://localhost&response_type=code&scope=read,activity:read,activity:read_all,profile:read_all
```
**What to do:**
- Copy the entire URL
- Keep it ready for the next step
---
## Step 3: Visit URL and Authorize
1. **Paste the authorization URL** in your browser
2. **Log in** to Strava if prompted
3. **Click "Authorize"** to grant permissions
4. You'll be **redirected** to a URL like:
```
http://localhost/?code=abc123xyz789&scope=read,activity:read,activity:read_all,profile:read_all
```
**Note:** You may see a "Page not found" error - this is normal! The important part is the URL in your browser's address bar.
---
## Step 4: Copy Authorization Code
From the redirect URL, copy **only the code parameter value**:
**Example:**
- Redirect URL: `http://localhost/?code=abc123xyz789&scope=...`
- Copy this part: `abc123xyz789`
**Important:**
- ⚠️ The code expires quickly (usually within 10 minutes)
- ⚠️ Copy it immediately after authorization
- ⚠️ The code is case-sensitive - copy it exactly
---
## Step 5: Complete Authentication
**Prompt:**
```
Complete Strava authentication with code: YOUR_CODE_HERE
```
**Replace `YOUR_CODE_HERE` with the code you copied in Step 4.**
**Tool:**
```python
complete_strava_auth(auth_code="YOUR_CODE_HERE")
```
**Expected Result:**
```json
{
"status": "success",
"message": "Strava authentication completed successfully!",
"refresh_token_preview": "b18579cb2...",
"env_file": ".env",
"next_steps": [
"Restart the MCP server to load the new credentials",
"Use check_auth_status() to verify the setup",
"Start using Strava API tools"
]
}
```
**What happens:**
- ✅ Refresh token is saved to `.env` file
- ✅ Access token is saved (optional)
- ✅ Expires timestamp is saved (optional)
---
## Step 6: Restart Server
After successful authentication, restart the MCP server to load the new refresh token:
```bash
# Kill existing server (if running)
pkill -f "src/server.py"
# Or if running on a specific port:
lsof -ti:9186 | xargs kill
# Start server again
uv run src/server.py --transport sse --port 9186
```
---
## Step 7: Verify It Worked
**Prompt:**
```
Check my Strava authentication status
```
**Expected Result:**
```json
{
"is_configured": true,
"has_client_id": true,
"has_client_secret": true,
"has_refresh_token": true,
"message": "Authentication is fully configured and ready to use!"
}
```
**If you see `has_refresh_token: true`, you're all set! 🎉**
---
## Quick Reference: All Steps
1. ✅ `Check my Strava authentication status` (verify credentials exist)
2. ✅ `Get the Strava authorization URL`
3. ✅ [Visit URL, authorize, copy code]
4. ✅ `Complete Strava authentication with code: YOUR_CODE`
5. ✅ [Restart server]
6. ✅ `Check my Strava authentication status` (verify refresh token exists)
---
## Troubleshooting
### "Client ID not found" error
**Solution:** Even though you thought credentials were set, they might not be. Use:
```python
save_credentials(client_id="...", client_secret="...")
```
Then proceed with Step 2.
### "Invalid authorization code" error
**Solution:**
- Code may have expired (they expire quickly)
- Make sure you copied the entire code value
- Try the authorization flow again
### "Error exchanging code for token" error
**Solution:**
- Double-check your Client ID and Client Secret are correct
- Verify the code is correct
- Make sure redirect URI matches Strava settings (`http://localhost`)
### Refresh token not saved
**Solution:**
- Check write permissions on `.env` file
- Verify the server has write access to the directory
- Check server logs for detailed error messages
---
## Alternative: One-Step Method
If you prefer, you can use the one-step method even when credentials are already set:
**Tool:**
```python
get_strava_auth_token(
client_id="YOUR_CLIENT_ID",
client_secret="YOUR_CLIENT_SECRET",
auth_code="YOUR_AUTHORIZATION_CODE"
)
```
This will:
- Save/update credentials (if needed)
- Exchange code for tokens
- Save refresh token
You still need to:
1. Get authorization URL (Step 2)
2. Visit and authorize (Step 3)
3. Copy code (Step 4)
4. Use the tool
5. Restart server (Step 6)
---
## Summary
When credentials are already set, the process is simpler:
- Skip credential saving step
- Get authorization URL
- Authorize and get code
- Complete authentication
- Restart server
- Verify
That's it! Your refresh token is now saved in `.env`.