Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions apps/sim/lib/oauth/oauth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,46 @@ describe('OAuth Token Refresh', () => {
})
})

it.concurrent(
'should rotate refresh token for Microsoft providers (microsoft, outlook, onedrive, sharepoint)',
async () => {
const microsoftProviders = [
'microsoft',
'outlook',
'onedrive',
'sharepoint',
'microsoft-excel',
'microsoft-teams',
'microsoft-planner',
'microsoft-ad',
'microsoft-dataverse',
]
const oldRefreshToken = 'old_microsoft_refresh_token'
const rotatedRefreshToken = 'rotated_microsoft_refresh_token'

for (const providerId of microsoftProviders) {
const mockFetch = vi.fn().mockResolvedValue({
ok: true,
json: async () => ({
access_token: 'new_access_token',
expires_in: 3600,
refresh_token: rotatedRefreshToken,
}),
})

const result = await withMockFetch(mockFetch, () =>
refreshOAuthToken(providerId, oldRefreshToken)
)

expect(result).toEqual({
accessToken: 'new_access_token',
expiresIn: 3600,
refreshToken: rotatedRefreshToken,
})
}
}
)

it.concurrent('should use original refresh token when new one is not provided', async () => {
const refreshToken = 'original_refresh_token'

Expand Down
1 change: 1 addition & 0 deletions apps/sim/lib/oauth/oauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1163,6 +1163,7 @@ function getProviderAuthConfig(provider: string): ProviderAuthConfig {
clientId,
clientSecret,
useBasicAuth: false,
supportsRefreshTokenRotation: true,
}
}
case 'linear': {
Expand Down
Loading