Skip to content

Conversation

@majiayu000
Copy link
Contributor

Summary

  • Add User-Agent header to Reddit OAuth token refresh requests
  • Reddit API requires User-Agent header for all requests, including token refresh
  • Without this header, requests fail with 403 error after initial token expires

Test plan

  • Added test to verify User-Agent header is included in Reddit OAuth requests
  • All existing OAuth tests pass (23 tests)

Fixes #1822

@vercel
Copy link

vercel bot commented Dec 22, 2025

@majiayu000 is attempting to deploy a commit to the Sim Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 22, 2025

Greptile Summary

This PR fixes Reddit OAuth token refresh failures by adding the required User-Agent header to Reddit API requests. Reddit's API blocks requests without a User-Agent header with a 403 error, which was causing token refresh failures after the initial token expired.

Key Changes:

  • Added User-Agent: sim-studio/1.0 (https://github.com/simstudioai/sim) header to Reddit OAuth configuration
  • Added test coverage to verify the User-Agent header is included in Reddit OAuth requests
  • Added Helm chart flexibility for custom network egress rules (unrelated infrastructure enhancement)

The implementation correctly leverages the existing additionalHeaders mechanism that's already used for GitHub's Accept header, ensuring consistency with the codebase patterns.

Confidence Score: 5/5

  • This PR is safe to merge with no risk - it's a minimal, well-tested bug fix
  • The fix directly addresses a documented Reddit API requirement, uses existing patterns (additionalHeaders), includes proper test coverage, and makes no breaking changes. The networkpolicy.yaml change is a safe infrastructure enhancement.
  • No files require special attention

Important Files Changed

Filename Overview
apps/sim/lib/oauth/oauth.ts Added User-Agent header to Reddit OAuth configuration to fix 403 errors during token refresh
apps/sim/lib/oauth/oauth.test.ts Added test to verify User-Agent header is included in Reddit OAuth requests
helm/sim/templates/networkpolicy.yaml Added support for custom egress rules configuration through Helm values

Sequence Diagram

sequenceDiagram
    participant Client
    participant OAuthLib
    participant Reddit API
    
    Client->>OAuthLib: refreshOAuthToken('reddit', refreshToken)
    OAuthLib->>OAuthLib: getProviderAuthConfig('reddit')
    Note over OAuthLib: Creates config with<br/>User-Agent header
    OAuthLib->>OAuthLib: buildAuthRequest(config, refreshToken)
    Note over OAuthLib: Adds headers:<br/>- Content-Type<br/>- User-Agent (NEW)<br/>- Authorization (Basic Auth)
    OAuthLib->>Reddit API: POST /api/v1/access_token<br/>with User-Agent header
    alt Success
        Reddit API-->>OAuthLib: {access_token, expires_in}
        OAuthLib-->>Client: {accessToken, expiresInSeconds}
    else Failure (403 without User-Agent)
        Reddit API-->>OAuthLib: 403 Forbidden
        OAuthLib-->>Client: null
    end
Loading

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 22, 2025

Greptile found no issues!

From now on, if a review finishes and we haven't found any issues, we will not post anything, but you can confirm that we reviewed your changes in the status check section.

This feature can be toggled off in your Code Review Settings by deselecting "Create a status check for each PR".

@vercel
Copy link

vercel bot commented Dec 22, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
docs Ready Ready Preview, Comment Dec 22, 2025 5:52pm

@waleedlatif1
Copy link
Collaborator

@majiayu000 do you mind rebasing so the branch only has your commit

Reddit API requires User-Agent header for all requests including OAuth
token refresh. Without it, requests fail with 403 error after the
initial token expires.

Fixes simstudioai#1822
@majiayu000 majiayu000 force-pushed the fix/reddit-oauth-user-agent branch from 3a6a9c9 to f562bde Compare December 23, 2025 03:30
@majiayu000
Copy link
Contributor Author

Done! Rebased onto the latest staging branch.

@icecrasher321 icecrasher321 merged commit e0d96e2 into simstudioai:staging Dec 23, 2025
1 of 2 checks passed
@majiayu000 majiayu000 deleted the fix/reddit-oauth-user-agent branch December 23, 2025 06:20
waleedlatif1 pushed a commit that referenced this pull request Dec 23, 2025
Reddit API requires User-Agent header for all requests including OAuth
token refresh. Without it, requests fail with 403 error after the
initial token expires.

Fixes #1822
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.

3 participants