Skip to content
Open
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
24 changes: 24 additions & 0 deletions apps/sim/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ export const auth = betterAuth({

// Common SSO provider patterns
...SSO_TRUSTED_PROVIDERS,
// Generic OAuth provider (if configured)
...(env.OAUTH_PROVIDER_ID ? [env.OAUTH_PROVIDER_ID] : []),
],
},
},
Expand Down Expand Up @@ -1584,6 +1586,28 @@ export const auth = betterAuth({
}
},
},
// Generic OAuth provider (Auth0, Okta, Keycloak, custom OIDC, etc.)
...(env.OAUTH_CLIENT_ID &&
env.OAUTH_CLIENT_SECRET &&
env.OAUTH_AUTHORIZATION_URL &&
env.OAUTH_TOKEN_URL &&
env.OAUTH_USERINFO_URL &&
env.OAUTH_PROVIDER_ID
? [
{
providerId: env.OAUTH_PROVIDER_ID,
clientId: env.OAUTH_CLIENT_ID,
clientSecret: env.OAUTH_CLIENT_SECRET,
authorizationUrl: env.OAUTH_AUTHORIZATION_URL,
tokenUrl: env.OAUTH_TOKEN_URL,
userInfoUrl: env.OAUTH_USERINFO_URL,
scopes: env.OAUTH_SCOPES
? env.OAUTH_SCOPES.split(' ').filter(Boolean)
: ['openid', 'profile', 'email'],
redirectURI: `${getBaseUrl()}/api/auth/oauth2/callback/${env.OAUTH_PROVIDER_ID}`,
},
Comment on lines +1597 to +1608
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: missing getUserInfo function - this will cause authentication to fail

All other genericOAuth providers in this file (github-repo, wealthbox, pipedrive, hubspot, salesforce, supabase, x, webflow) include a getUserInfo function that fetches user data from the provider and returns it in Better Auth's expected format.

The generic OAuth configuration needs a getUserInfo async function that:

  1. Fetches user data from OAUTH_USERINFO_URL using the access token
  2. Maps the response to Better Auth's user schema (id, name, email, emailVerified, image, createdAt, updatedAt)
  3. Handles errors and returns null on failure

See apps/sim/lib/auth.ts:833-868 (Salesforce) for a standard OIDC implementation pattern.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/lib/auth.ts
Line: 1597:1608

Comment:
**logic:** missing `getUserInfo` function - this will cause authentication to fail

All other genericOAuth providers in this file (github-repo, wealthbox, pipedrive, hubspot, salesforce, supabase, x, webflow) include a `getUserInfo` function that fetches user data from the provider and returns it in Better Auth's expected format.

The generic OAuth configuration needs a `getUserInfo` async function that:
1. Fetches user data from `OAUTH_USERINFO_URL` using the access token
2. Maps the response to Better Auth's user schema (id, name, email, emailVerified, image, createdAt, updatedAt)
3. Handles errors and returns null on failure

See `apps/sim/lib/auth.ts:833-868` (Salesforce) for a standard OIDC implementation pattern.

How can I resolve this? If you propose a fix, please make it concise.

]
: []),
],
}),
// Include SSO plugin when enabled
Expand Down
7 changes: 7 additions & 0 deletions apps/sim/lib/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ export const env = createEnv({
GOOGLE_CLIENT_SECRET: z.string().optional(), // Google OAuth client secret
GITHUB_CLIENT_ID: z.string().optional(), // GitHub OAuth client ID for GitHub integration
GITHUB_CLIENT_SECRET: z.string().optional(), // GitHub OAuth client secret
OAUTH_CLIENT_ID: z.string().optional(), // OAuth client ID
OAUTH_CLIENT_SECRET: z.string().optional(), // OAuth client secret
OAUTH_AUTHORIZATION_URL: z.string().optional(), // OAuth authorization URL
OAUTH_TOKEN_URL: z.string().optional(), // OAuth token URL
OAUTH_USERINFO_URL: z.string().optional(), // OAuth userinfo URL
Comment on lines +179 to +181
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: missing URL validation - use .url() validator like other URL fields

Other URL fields in this file use .url() validation (e.g., DATABASE_URL: z.string().url() on line 19, OLLAMA_URL: z.string().url().optional() on line 79). This validates URL format and prevents configuration errors.

Suggested change
OAUTH_AUTHORIZATION_URL: z.string().optional(), // OAuth authorization URL
OAUTH_TOKEN_URL: z.string().optional(), // OAuth token URL
OAUTH_USERINFO_URL: z.string().optional(), // OAuth userinfo URL
OAUTH_AUTHORIZATION_URL: z.string().url().optional(), // OAuth authorization URL
OAUTH_TOKEN_URL: z.string().url().optional(), // OAuth token URL
OAUTH_USERINFO_URL: z.string().url().optional(), // OAuth userinfo URL
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/lib/env.ts
Line: 179:181

Comment:
**style:** missing URL validation - use `.url()` validator like other URL fields

Other URL fields in this file use `.url()` validation (e.g., `DATABASE_URL: z.string().url()` on line 19, `OLLAMA_URL: z.string().url().optional()` on line 79). This validates URL format and prevents configuration errors.

```suggestion
    OAUTH_AUTHORIZATION_URL:               z.string().url().optional(),            // OAuth authorization URL
    OAUTH_TOKEN_URL:                       z.string().url().optional(),            // OAuth token URL
    OAUTH_USERINFO_URL:                    z.string().url().optional(),            // OAuth userinfo URL
```

How can I resolve this? If you propose a fix, please make it concise.

OAUTH_SCOPES: z.string().optional(), // OAuth scopes
OAUTH_PROVIDER_ID: z.string().optional(), // OAuth provider ID
GITHUB_REPO_CLIENT_ID: z.string().optional(), // GitHub OAuth client ID for repo access
GITHUB_REPO_CLIENT_SECRET: z.string().optional(), // GitHub OAuth client secret for repo access
X_CLIENT_ID: z.string().optional(), // X (Twitter) OAuth client ID
Expand Down
28 changes: 28 additions & 0 deletions helm/sim/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,34 @@
"type": "string",
"description": "GitHub OAuth client secret"
},
"OAUTH_CLIENT_ID": {
"type": "string",
"description": "OAuth client ID"
},
"OAUTH_CLIENT_SECRET": {
"type": "string",
"description": "OAuth client secret"
},
"OAUTH_AUTHORIZATION_URL": {
"type": "string",
"description": "OAuth authorization URL"
},
"OAUTH_TOKEN_URL": {
"type": "string",
"description": "OAuth token URL"
},
"OAUTH_USERINFO_URL": {
"type": "string",
"description": "OAuth userinfo URL"
},
"OAUTH_SCOPES": {
"type": "string",
"description": "OAuth scopes (default: openid profile email)"
},
"OAUTH_PROVIDER_ID": {
"type": "string",
"description": "OAuth provider ID"
},
"OPENAI_API_KEY": {
"type": "string",
"description": "Primary OpenAI API key"
Expand Down
11 changes: 10 additions & 1 deletion helm/sim/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,16 @@ app:
GOOGLE_CLIENT_SECRET: "" # Google OAuth client secret
GITHUB_CLIENT_ID: "" # GitHub OAuth client ID
GITHUB_CLIENT_SECRET: "" # GitHub OAuth client secret


# Generic OAuth Provider Configuration (for Auth0, Okta, Keycloak, custom OIDC providers, etc.)
OAUTH_CLIENT_ID: "" # OAuth client ID for generic OAuth provider
OAUTH_CLIENT_SECRET: "" # OAuth client secret for generic OAuth provider
OAUTH_AUTHORIZATION_URL: "" # Authorization endpoint URL (e.g., https://your-domain.auth0.com/authorize)
OAUTH_TOKEN_URL: "" # Token endpoint URL (e.g., https://your-domain.auth0.com/oauth/token)
OAUTH_USERINFO_URL: "" # User info endpoint URL (e.g., https://your-domain.auth0.com/userinfo)
OAUTH_SCOPES: "openid profile email" # OAuth scopes (default: openid profile email)
OAUTH_PROVIDER_ID: "" # Provider identifier for Better Auth's genericOAuth plugin (e.g., auth0, okta, custom)

# AI Provider API Keys (leave empty if not using)
OPENAI_API_KEY: "" # Primary OpenAI API key
OPENAI_API_KEY_1: "" # Additional OpenAI API key for load balancing
Expand Down