Skip to content

Commit 40413cb

Browse files
committed
fix(auth): keep OAuth grant revocation out of the auth module graph
1 parent 4e554dc commit 40413cb

3 files changed

Lines changed: 15 additions & 14 deletions

File tree

‎apps/sim/lib/auth/auth.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import {
5555
recordPasswordResetAudit,
5656
} from '@/lib/auth/lifecycle-audit'
5757
import { hashOAuthToken } from '@/lib/auth/oauth-access-token'
58+
import { revokeUserOAuthGrants } from '@/lib/auth/oauth-grants'
5859
import {
5960
consentRequestNamesClient,
6061
OAUTH_ACCESS_TOKEN_PREFIX,
@@ -67,7 +68,6 @@ import {
6768
SIM_CLI_CLIENT_ID,
6869
} from '@/lib/auth/oauth-provider'
6970
import { bindOAuthIssuedResource, oauthResourcePlugin } from '@/lib/auth/oauth-resource'
70-
import { revokeUserOAuthGrants } from '@/lib/auth/oauth-token-family'
7171
import { getSessionCookieCacheVersion } from '@/lib/auth/security-policy'
7272
import { prepareSessionForCreation } from '@/lib/auth/session-hooks'
7373
import { clampExpiryForSession } from '@/lib/auth/session-policy'

‎apps/sim/lib/auth/oauth-grants.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { db } from '@sim/db'
2+
import { oauthAccessToken, oauthTokenFamily } from '@sim/db/schema'
3+
import { eq } from 'drizzle-orm'
4+
import type { DbOrTx } from '@/lib/db/types'
5+
6+
/**
7+
* Revokes every refresh family and access token a user holds. Families outlive the session that
8+
* minted them (`session_id` is set null on delete), so deleting sessions alone leaves them
9+
* rotatable. Consents are kept, so a legitimate client re-authorizes without a new consent prompt.
10+
*/
11+
export async function revokeUserOAuthGrants(userId: string, database: DbOrTx = db): Promise<void> {
12+
await database.delete(oauthTokenFamily).where(eq(oauthTokenFamily.userId, userId))
13+
await database.delete(oauthAccessToken).where(eq(oauthAccessToken.userId, userId))
14+
}

‎apps/sim/lib/auth/oauth-token-family.ts‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -493,19 +493,6 @@ export async function rotateOAuthRefreshToken(
493493
})
494494
}
495495

496-
/**
497-
* Revokes every refresh family and access token a user holds. Families outlive the session that
498-
* minted them (`session_id` is set null on delete), so deleting sessions alone leaves them
499-
* rotatable. Consents are kept, so a legitimate client re-authorizes without a new consent prompt.
500-
*/
501-
export async function revokeUserOAuthGrants(
502-
userId: string,
503-
database: OAuthDatabase = db
504-
): Promise<void> {
505-
await database.delete(oauthTokenFamily).where(eq(oauthTokenFamily.userId, userId))
506-
await database.delete(oauthAccessToken).where(eq(oauthAccessToken.userId, userId))
507-
}
508-
509496
/** Revokes one refresh family or one opaque access token. Unknown tokens are a successful no-op. */
510497
export async function revokeOAuthToken(
511498
input: { credentials: OAuthClientCredentials; token: string },

0 commit comments

Comments
 (0)