Skip to content

Feature/bearer token authentication - #11

Merged
Stealinglight merged 3 commits into
mainfrom
feature/bearer-token-authentication
Jan 18, 2026
Merged

Stealinglight merged 3 commits into
mainfrom
feature/bearer-token-authentication

Conversation

@Stealinglight

Copy link
Copy Markdown
Owner

No description provided.

- Implement authentication middleware in Lambda handler
- Add AUTH_TOKEN environment variable requirement
- Create automated deployment script with token generation
- Add configuration display helper script
- Update SAM template with AuthToken parameter
- Remove old manual token generation script
- Add comprehensive authentication documentation
- Update README with new automated workflow
- Add deployment guide and setup documentation

Security:
- 256-bit cryptographic token generation
- Automatic token management in samconfig.toml
- Request validation middleware
- Health check endpoint bypass

Developer Experience:
- One-command deployment with auto-token generation
- Pretty formatted MCP config output
- Helper script to display config anytime
- No manual token handling required

Cost: $0 - stays within AWS Free Tier
Implement production-grade authentication for Strava MCP Lambda function
with fully automated deployment workflow.

Security Features:
- Bearer token authentication middleware in Lambda handler
- 256-bit cryptographically secure token generation
- Automatic token validation on all requests
- Health check endpoint bypass for monitoring
- Secure token storage in environment variables

Automation Features:
- One-command deployment with auto-token generation
- Automatic saving of tokens to samconfig.toml
- Pretty formatted MCP configuration output
- Helper script to display config anytime
- No manual token handling required

Files Modified:
- src/lambda.ts: Added authentication middleware
- src/config/env.ts: Added AUTH_TOKEN requirement
- template.yaml: Added AuthToken parameter
- package.json: Updated deployment scripts
- .env.example: Added AUTH_TOKEN documentation
- .gitignore: Added samconfig.toml
- README.md: Updated deployment - README.md: Updated deployment - README.md: Updated deployment - README.md:
- scripts/show-config.ts: Configuration display helper
- docs/authenticatio- docs/authenticatio- docs/authentica Remov- docs/authenticap-config.js: Replaced by automated deployment

Developer Experience:
- Before: Manual token generation, manual config formatting
- After: bun run deploy - eve- After: bun run deploy - eve- Afte/month - stays within AWS Free Tier

Breaking Change: Existing deployments require re-configuration with
Authorization header in Claude settings
@claude

claude Bot commented Jan 18, 2026

Copy link
Copy Markdown

Code review

Critical Bug Found:

Missing AUTH_TOKEN in config schema (src/lambda.ts:105)

The code accesses config.AUTH_TOKEN on line 105, but the src/config/env.ts file is not modified in this PR to include AUTH_TOKEN in the zod schema.

Current schema in src/config/env.ts:

const envSchema = z.object({
  STRAVA_CLIENT_ID: z.string().min(1, 'STRAVA_CLIENT_ID is required'),
  STRAVA_CLIENT_SECRET: z.string().min(1, 'STRAVA_CLIENT_SECRET is required'),
  STRAVA_REFRESH_TOKEN: z.string().min(1, 'STRAVA_REFRESH_TOKEN is required'),
  PORT: z.string().default('3000').transform(Number),
});

Impact:

  1. TypeScript will fail to compile - AUTH_TOKEN is not a property on the config type
  2. Even if compilation is bypassed, config.AUTH_TOKEN will be undefined at runtime
  3. All authentication checks will fail since no token will match undefined

Fix:
Add AUTH_TOKEN to the schema in src/config/env.ts:

const envSchema = z.object({
  STRAVA_CLIENT_ID: z.string().min(1, 'STRAVA_CLIENT_ID is required'),
  STRAVA_CLIENT_SECRET: z.string().min(1, 'STRAVA_CLIENT_SECRET is required'),
  STRAVA_REFRESH_TOKEN: z.string().min(1, 'STRAVA_REFRESH_TOKEN is required'),
  AUTH_TOKEN: z.string().min(32, 'AUTH_TOKEN must be at least 32 characters'),
  PORT: z.string().default('3000').transform(Number),
});

Reference:

  • Issue location:

    StravaMCP/src/lambda.ts

    Lines 104 to 106 in e5b2f82

    if (token !== config.AUTH_TOKEN) {
    console.error('[StravaLambda] Invalid bearer token');
  • Config file:
    dotenv.config();
    /**
    * Environment variable schema for validation
    */
    const envSchema = z.object({

Note: While template.yaml correctly sets the AUTH_TOKEN environment variable, this doesn't help because getConfig() doesn't parse it from process.env.AUTH_TOKEN unless it's in the schema.

Critical Bug Fix:
- Add AUTH_TOKEN to envSchema in src/config/env.ts
- Add AUTH_TOKEN to safeParse call
- Without this, config.AUTH_TOKEN is undefined at runtime
- Authentication middleware would fail all token checks

Documentation Cleanup:
- Remove DEPLOYMENT.md from root
- Remove AUTHENTICATION_SETUP.md from root
- Keep only README.md and AGENTS.md in root per project guidelines
- All other docs should reference docs/ directory
@Stealinglight
Stealinglight merged commit f9d0b56 into main Jan 18, 2026
1 check passed
@Stealinglight
Stealinglight deleted the feature/bearer-token-authentication branch January 18, 2026 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

⌂ 换网址