Skip to content

Commit 8de7611

Browse files
author
aadamgough
committed
reformatted to PAT from oauth
1 parent 23a7d87 commit 8de7611

File tree

20 files changed

+50
-676
lines changed

20 files changed

+50
-676
lines changed

apps/sim/app/api/auth/oauth/utils.ts

Lines changed: 3 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ export async function getOAuthToken(userId: string, providerId: string): Promise
6969
accessTokenExpiresAt: account.accessTokenExpiresAt,
7070
accountId: account.accountId,
7171
providerId: account.providerId,
72-
password: account.password, // Include password field for Snowflake OAuth credentials
7372
})
7473
.from(account)
7574
.where(and(eq(account.userId, userId), eq(account.providerId, providerId)))
@@ -96,25 +95,8 @@ export async function getOAuthToken(userId: string, providerId: string): Promise
9695
)
9796

9897
try {
99-
// Extract account URL and OAuth credentials for Snowflake
100-
let metadata: { accountUrl?: string; clientId?: string; clientSecret?: string } | undefined
101-
if (providerId === 'snowflake' && credential.accountId) {
102-
metadata = { accountUrl: credential.accountId }
103-
104-
// Extract clientId and clientSecret from the password field (stored as JSON)
105-
if (credential.password) {
106-
try {
107-
const oauthCredentials = JSON.parse(credential.password)
108-
metadata.clientId = oauthCredentials.clientId
109-
metadata.clientSecret = oauthCredentials.clientSecret
110-
} catch (e) {
111-
logger.error('Failed to parse Snowflake OAuth credentials', { error: e })
112-
}
113-
}
114-
}
115-
11698
// Use the existing refreshOAuthToken function
117-
const refreshResult = await refreshOAuthToken(providerId, credential.refreshToken!, metadata)
99+
const refreshResult = await refreshOAuthToken(providerId, credential.refreshToken!)
118100

119101
if (!refreshResult) {
120102
logger.error(`Failed to refresh token for user ${userId}, provider ${providerId}`, {
@@ -197,27 +179,9 @@ export async function refreshAccessTokenIfNeeded(
197179
if (shouldRefresh) {
198180
logger.info(`[${requestId}] Token expired, attempting to refresh for credential`)
199181
try {
200-
// Extract account URL and OAuth credentials for Snowflake
201-
let metadata: { accountUrl?: string; clientId?: string; clientSecret?: string } | undefined
202-
if (credential.providerId === 'snowflake' && credential.accountId) {
203-
metadata = { accountUrl: credential.accountId }
204-
205-
// Extract clientId and clientSecret from the password field (stored as JSON)
206-
if (credential.password) {
207-
try {
208-
const oauthCredentials = JSON.parse(credential.password)
209-
metadata.clientId = oauthCredentials.clientId
210-
metadata.clientSecret = oauthCredentials.clientSecret
211-
} catch (e) {
212-
logger.error('Failed to parse Snowflake OAuth credentials', { error: e })
213-
}
214-
}
215-
}
216-
217182
const refreshedToken = await refreshOAuthToken(
218183
credential.providerId,
219-
credential.refreshToken!,
220-
metadata
184+
credential.refreshToken!
221185
)
222186

223187
if (!refreshedToken) {
@@ -289,28 +253,7 @@ export async function refreshTokenIfNeeded(
289253
}
290254

291255
try {
292-
// Extract account URL and OAuth credentials for Snowflake
293-
let metadata: { accountUrl?: string; clientId?: string; clientSecret?: string } | undefined
294-
if (credential.providerId === 'snowflake' && credential.accountId) {
295-
metadata = { accountUrl: credential.accountId }
296-
297-
// Extract clientId and clientSecret from the password field (stored as JSON)
298-
if (credential.password) {
299-
try {
300-
const oauthCredentials = JSON.parse(credential.password)
301-
metadata.clientId = oauthCredentials.clientId
302-
metadata.clientSecret = oauthCredentials.clientSecret
303-
} catch (e) {
304-
logger.error('Failed to parse Snowflake OAuth credentials', { error: e })
305-
}
306-
}
307-
}
308-
309-
const refreshResult = await refreshOAuthToken(
310-
credential.providerId,
311-
credential.refreshToken!,
312-
metadata
313-
)
256+
const refreshResult = await refreshOAuthToken(credential.providerId, credential.refreshToken!)
314257

315258
if (!refreshResult) {
316259
logger.error(`[${requestId}] Failed to refresh token for credential`)

apps/sim/app/api/auth/snowflake/authorize/route.ts

Lines changed: 0 additions & 92 deletions
This file was deleted.

0 commit comments

Comments
 (0)