Skip to content

Commit 426c7d6

Browse files
majiayu000waleedlatif1
authored andcommitted
fix(oauth): add User-Agent header to Reddit token refresh (#2517)
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
1 parent a61506d commit 426c7d6

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

apps/sim/lib/oauth/oauth.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,17 @@ describe('OAuth Token Refresh', () => {
214214
const [, requestOptions] = (mockFetch as Mock).mock.calls[0]
215215
expect(requestOptions.headers.Accept).toBe('application/json')
216216
})
217+
218+
it('should include User-Agent header for Reddit requests', async () => {
219+
const refreshToken = 'test_refresh_token'
220+
221+
await refreshOAuthToken('reddit', refreshToken)
222+
223+
const [, requestOptions] = (mockFetch as Mock).mock.calls[0]
224+
expect(requestOptions.headers['User-Agent']).toBe(
225+
'sim-studio/1.0 (https://github.com/simstudioai/sim)'
226+
)
227+
})
217228
})
218229

219230
describe('Error Handling', () => {

apps/sim/lib/oauth/oauth.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,9 @@ function getProviderAuthConfig(provider: string): ProviderAuthConfig {
13601360
clientId,
13611361
clientSecret,
13621362
useBasicAuth: true,
1363+
additionalHeaders: {
1364+
'User-Agent': 'sim-studio/1.0 (https://github.com/simstudioai/sim)',
1365+
},
13631366
}
13641367
}
13651368
case 'wealthbox': {

0 commit comments

Comments
 (0)