Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

feat(auth): add support for custom OAuth/OIDC provider integration

Andrej Acevskif67a6f66b616
diff --git a/apps/api/src/auth.ts b/apps/api/src/auth.ts
index d5444b253..e40efd14c 100644
--- a/apps/api/src/auth.ts
+++ b/apps/api/src/auth.ts
@@ -5,6 +5,7 @@ import { drizzleAdapter } from "better-auth/adapters/drizzle";
import {
anonymous,
createAuthMiddleware,
+ genericOAuth,
lastLoginMethod,
magicLink,
organization,
@@ -178,6 +179,22 @@ export const auth = betterAuth({
);
},
}),
+ genericOAuth({
+ config: [
+ {
+ providerId: "custom",
+ clientId: process.env.CUSTOM_OAUTH_CLIENT_ID || "",
+ clientSecret: process.env.CUSTOM_OAUTH_CLIENT_SECRET,
+ authorizationUrl: process.env.CUSTOM_OAUTH_AUTHORIZATION_URL || "",
+ tokenUrl: process.env.CUSTOM_OAUTH_TOKEN_URL || "",
+ userInfoUrl: process.env.CUSTOM_OAUTH_USER_INFO_URL || "",
+ scopes: process.env.CUSTOM_OAUTH_SCOPES?.split(",") || [],
+ responseType: process.env.CUSTOM_OAUTH_RESPONSE_TYPE || "code",
+ discoveryUrl: process.env.CUSTOM_OAUTH_DISCOVERY_URL || "",
+ pkce: process.env.CUSTOM_AUTH_PKCE !== "false",
+ },
+ ],
+ }),
],
session: {
cookieCache: {
diff --git a/apps/api/src/utils/get-settings.ts b/apps/api/src/utils/get-settings.ts
index e23ce5daf..8c02cee63 100644
--- a/apps/api/src/utils/get-settings.ts
+++ b/apps/api/src/utils/get-settings.ts
@@ -18,6 +18,9 @@ function getSettings() {
hasGoogleSignIn:
Boolean(process.env.GOOGLE_CLIENT_ID) &&
Boolean(process.env.GOOGLE_CLIENT_SECRET),
+ hasCustomOAuth:
+ Boolean(process.env.CUSTOM_OAUTH_CLIENT_ID) &&
+ Boolean(process.env.CUSTOM_OAUTH_CLIENT_SECRET),
};
}
diff --git a/apps/docs/content/docs/installation/environment-variables.mdx b/apps/docs/content/docs/installation/environment-variables.mdx
index 301e074d7..c63e4a223 100644
--- a/apps/docs/content/docs/installation/environment-variables.mdx
+++ b/apps/docs/content/docs/installation/environment-variables.mdx
@@ -13,6 +13,8 @@ The variables are split up into the following sections:
- [Database](#database)
- [Authentication](#authentication)
- [GitHub SSO & Integration](#github-sso-&-integration)
+- [Google SSO](#google-sso)
+- [Custom OAuth/OIDC](#custom-oauth-oidc)
- [SMTP Configuration](#smtp-configuration)
## Required variables
@@ -58,13 +60,27 @@ Name | Description |
| `GITHUB_WEBHOOK_SECRET` | The GitHub webhook secret.
| `GITHUB_PRIVATE_KEY` | The GitHub private key.
-### Google SSO & Integration
+### Google SSO
Name | Description |
--- | --- |
| `GOOGLE_CLIENT_ID` | The Google client ID.
| `GOOGLE_CLIENT_SECRET` | The Google client secret.
+### Custom OAuth/OIDC
+
+Name | Description |
+--- | --- |
+| `CUSTOM_OAUTH_CLIENT_ID` | OAuth client ID from your provider.
+| `CUSTOM_OAUTH_CLIENT_SECRET` | OAuth client secret from your provider.
+| `CUSTOM_OAUTH_AUTHORIZATION_URL` | Authorization endpoint URL.
+| `CUSTOM_OAUTH_TOKEN_URL` | Token exchange endpoint URL.
+| `CUSTOM_OAUTH_USER_INFO_URL` | User info endpoint URL.
+| `CUSTOM_OAUTH_DISCOVERY_URL` | (Optional) OpenID Connect discovery document URL.
+| `CUSTOM_OAUTH_SCOPES` | (Optional) Comma-separated list of OAuth scopes. Default: `profile,email`.
+| `CUSTOM_OAUTH_RESPONSE_TYPE` | (Optional) OAuth response type. Default: `code`.
+| `CUSTOM_AUTH_PKCE` | (Optional) Enable/disable PKCE. Default: `true`.
+
### SMTP Configuration
Name | Description |
@@ -79,6 +95,7 @@ Name | Description |
## Key points
-- If you enable GitHub SSO, you need to set up the GitHub app which is used to authenticate users in the [GitHub Developer Settings](https://github.com/settings/developers).
-- If you enable Google SSO, you need to set up the Google app which is used to authenticate users in the [Google Cloud Console](https://console.cloud.google.com/).
+- If you enable GitHub SSO, you need to set up the GitHub app which is used to authenticate users in the [GitHub Developer Settings](https://github.com/settings/developers). See the [GitHub SSO guide](/docs/social-providers/github).
+- If you enable Google SSO, you need to set up the Google app which is used to authenticate users in the [Google Cloud Console](https://console.cloud.google.com/). See the [Google SSO guide](/docs/social-providers/google).
+- If you enable Custom OAuth/OIDC, you need to configure your identity provider with the appropriate redirect URI. See the [Custom OAuth/OIDC guide](/docs/social-providers/custom-oauth).
- If you have enabled SMTP, your sign in will be done via email using a magic link.
diff --git a/apps/docs/content/docs/social-providers/custom-oauth.mdx b/apps/docs/content/docs/social-providers/custom-oauth.mdx
new file mode 100644
index 000000000..dcdfaf51c
--- /dev/null
+++ b/apps/docs/content/docs/social-providers/custom-oauth.mdx
@@ -0,0 +1,170 @@
+---
+title: Custom OAuth/OIDC
+description: Configure Kaneo with your custom OpenID Connect (OIDC) provider.
+---
+
+## Overview
+
+Kaneo supports custom OAuth 2.0 and OpenID Connect (OIDC) providers, allowing you to integrate with any standards-compliant identity provider such as Keycloak, Auth0, Okta, Azure AD, or self-hosted solutions like Pocket ID.
+
+## Configuration
+
+To configure a custom OAuth/OIDC provider, you need to set the following environment variables in your `.env` file:
+
+### Required Variables
+
+| Variable | Description | Example |
+|----------|-------------|---------|
+| `CUSTOM_OAUTH_CLIENT_ID` | OAuth client ID from your provider | `2b1ae9df-8d25-4dbc-8cc8-f8f2c1ef6bd0` |
+| `CUSTOM_OAUTH_CLIENT_SECRET` | OAuth client secret from your provider | `NzDjplDsdQyP062wTmkZ8kyiaziBag0N` |
+| `CUSTOM_OAUTH_AUTHORIZATION_URL` | Authorization endpoint URL | `https://id.example.com/authorize` |
+| `CUSTOM_OAUTH_TOKEN_URL` | Token exchange endpoint URL | `https://id.example.com/api/oidc/token` |
+| `CUSTOM_OAUTH_USER_INFO_URL` | User info endpoint URL | `https://id.example.com/api/oidc/userinfo` |
+
+### Optional Variables
+
+| Variable | Description | Default |
+|----------|-------------|---------|
+| `CUSTOM_OAUTH_DISCOVERY_URL` | OpenID Connect discovery document URL | - |
+| `CUSTOM_OAUTH_SCOPES` | Comma-separated list of OAuth scopes | `profile,email` |
+| `CUSTOM_OAUTH_RESPONSE_TYPE` | OAuth response type | `code` |
+| `CUSTOM_AUTH_PKCE` | Enable/disable PKCE (Proof Key for Code Exchange) | `true` |
+
+## Setup Steps
+
+### 1. Configure Your OAuth Provider
+
+First, create an OAuth 2.0 or OIDC application in your identity provider:
+
+1. Log in to your identity provider's admin console
+2. Create a new OAuth 2.0 or OIDC application
+3. Set the redirect URI to: `{KANEO_API_URL}/api/auth/callback/custom`
+ - Example: `https://api.kaneo.example.com/api/auth/callback/custom`
+4. Copy the client ID and client secret
+5. Note the authorization, token, and userinfo endpoint URLs
+
+### 2. Set Environment Variables
+
+Add the following to your `.env` file:
+
+```bash
+# Custom OAuth/OIDC Configuration
+CUSTOM_OAUTH_CLIENT_ID=your-client-id
+CUSTOM_OAUTH_CLIENT_SECRET=your-client-secret
+CUSTOM_OAUTH_AUTHORIZATION_URL=https://your-idp.com/authorize
+CUSTOM_OAUTH_TOKEN_URL=https://your-idp.com/oauth/token
+CUSTOM_OAUTH_USER_INFO_URL=https://your-idp.com/oauth/userinfo
+
+# Optional: Use discovery URL for automatic configuration
+CUSTOM_OAUTH_DISCOVERY_URL=https://your-idp.com/.well-known/openid-configuration
+
+# Optional: Customize scopes
+CUSTOM_OAUTH_SCOPES=profile,email,openid
+
+# Optional: Disable PKCE if your provider doesn't support it
+CUSTOM_AUTH_PKCE=false
+```
+
+### 3. Restart Services
+
+After updating the environment variables, restart your Kaneo services:
+
+```bash
+docker compose restart
+```
+
+## Example Configurations
+
+### Pocket ID
+
+```bash
+CUSTOM_OAUTH_CLIENT_ID=2b1ae9df-8d25-4dbc-8cc8-f8f2c1ef6bd0
+CUSTOM_OAUTH_CLIENT_SECRET=NzDjplDsdQyP062wTmkZ8kyiaziBag0N
+CUSTOM_OAUTH_AUTHORIZATION_URL=https://4c6332d2.demo.pocket-id.org/authorize
+CUSTOM_OAUTH_TOKEN_URL=https://4c6332d2.demo.pocket-id.org/api/oidc/token
+CUSTOM_OAUTH_USER_INFO_URL=https://4c6332d2.demo.pocket-id.org/api/oidc/userinfo
+CUSTOM_OAUTH_DISCOVERY_URL=https://4c6332d2.demo.pocket-id.org/.well-known/openid-configuration
+CUSTOM_OAUTH_SCOPES=profile,email
+```
+
+### Keycloak
+
+```bash
+CUSTOM_OAUTH_CLIENT_ID=kaneo-client
+CUSTOM_OAUTH_CLIENT_SECRET=your-secret-here
+CUSTOM_OAUTH_DISCOVERY_URL=https://keycloak.example.com/realms/your-realm/.well-known/openid-configuration
+CUSTOM_OAUTH_SCOPES=openid,profile,email
+```
+
+### Auth0
+
+```bash
+CUSTOM_OAUTH_CLIENT_ID=your-client-id
+CUSTOM_OAUTH_CLIENT_SECRET=your-client-secret
+CUSTOM_OAUTH_AUTHORIZATION_URL=https://your-tenant.auth0.com/authorize
+CUSTOM_OAUTH_TOKEN_URL=https://your-tenant.auth0.com/oauth/token
+CUSTOM_OAUTH_USER_INFO_URL=https://your-tenant.auth0.com/userinfo
+CUSTOM_OAUTH_SCOPES=openid,profile,email
+```
+
+## Usage
+
+Once configured, users will see a "Continue with OIDC" button on the sign-in page. The system will automatically remember the last used login method for each user.
+
+## Troubleshooting
+
+### "Invalid code verifier" Error
+
+This error typically indicates a PKCE configuration issue. Try setting:
+
+```bash
+CUSTOM_AUTH_PKCE=false
+```
+
+Some OAuth providers don't support PKCE or have it disabled by default.
+
+### Missing User Information
+
+Ensure your OAuth scopes include at least `profile` and `email`:
+
+```bash
+CUSTOM_OAUTH_SCOPES=profile,email
+```
+
+Some providers require `openid` scope as well:
+
+```bash
+CUSTOM_OAUTH_SCOPES=openid,profile,email
+```
+
+### Redirect URI Mismatch
+
+Verify that your redirect URI in the OAuth provider matches exactly:
+
+```
+{KANEO_API_URL}/api/auth/callback/custom
+```
+
+For example, if `KANEO_API_URL=https://api.kaneo.example.com`, the redirect URI should be:
+
+```
+https://api.kaneo.example.com/api/auth/callback/custom
+```
+
+## Discovery URL
+
+If your provider supports OpenID Connect, you can use the discovery URL to automatically configure most settings:
+
+```bash
+CUSTOM_OAUTH_DISCOVERY_URL=https://your-idp.com/.well-known/openid-configuration
+```
+
+This will automatically discover the authorization, token, and userinfo endpoints. However, you still need to provide the client ID and secret.
+
+## Security Notes
+
+- Always use HTTPS in production
+- Keep your client secret secure and never commit it to version control
+- Enable PKCE when possible for enhanced security
+- Use the most restrictive scopes necessary for your use case
+
diff --git a/apps/docs/content/docs/social-providers/meta.json b/apps/docs/content/docs/social-providers/meta.json
index edde9a862..6e55140e8 100644
--- a/apps/docs/content/docs/social-providers/meta.json
+++ b/apps/docs/content/docs/social-providers/meta.json
@@ -1,6 +1,6 @@
{
"title": "Social Providers",
"icon": "Users",
- "pages": ["github", "google"],
+ "pages": ["github", "google", "custom-oauth"],
"defaultOpen": true
}
diff --git a/apps/docs/next-env.d.ts b/apps/docs/next-env.d.ts
index 9edff1c7c..c4b7818fb 100644
--- a/apps/docs/next-env.d.ts
+++ b/apps/docs/next-env.d.ts
@@ -1,6 +1,6 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
-import "./.next/types/routes.d.ts";
+import "./.next/dev/types/routes.d.ts";
// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
diff --git a/apps/web/src/components/auth/toggle.tsx b/apps/web/src/components/auth/toggle.tsx
index 10b15b841..1103d706e 100644
--- a/apps/web/src/components/auth/toggle.tsx
+++ b/apps/web/src/components/auth/toggle.tsx
@@ -15,7 +15,7 @@ export function AuthToggle({ message, linkText, linkTo }: AuthToggleProps) {
}
return (
- <div className="text-center text-sm text-muted-foreground">
+ <div className="text-center text-sm text-muted-foreground mt-3">
{message}{" "}
<Link
to={linkTo}
diff --git a/apps/web/src/lib/auth-client.ts b/apps/web/src/lib/auth-client.ts
index e8dbb86a9..fbf30baa5 100644
--- a/apps/web/src/lib/auth-client.ts
+++ b/apps/web/src/lib/auth-client.ts
@@ -1,5 +1,6 @@
import {
anonymousClient,
+ genericOAuthClient,
lastLoginMethodClient,
magicLinkClient,
organizationClient,
@@ -32,5 +33,6 @@ export const authClient = createAuthClient({
owner,
},
}),
+ genericOAuthClient(),
],
});
diff --git a/apps/web/src/routes/auth/sign-in.tsx b/apps/web/src/routes/auth/sign-in.tsx
index 921d22501..ccfbb8a63 100644
--- a/apps/web/src/routes/auth/sign-in.tsx
+++ b/apps/web/src/routes/auth/sign-in.tsx
@@ -1,5 +1,5 @@
import { createFileRoute, useNavigate } from "@tanstack/react-router";
-import { Github, UserCheck } from "lucide-react";
+import { Github, KeyRound, UserCheck } from "lucide-react";
import { useState } from "react";
import { toast } from "sonner";
import PageTitle from "@/components/page-title";
@@ -19,9 +19,10 @@ export const Route = createFileRoute("/auth/sign-in")({
function SignIn() {
const navigate = useNavigate();
- const [isGuestLoading, setIsGuestLoading] = useState(false);
+ const [isCustomOAuthLoading, setIsCustomOAuthLoading] = useState(false);
const [isGithubLoading, setIsGithubLoading] = useState(false);
const [isGoogleLoading, setIsGoogleLoading] = useState(false);
+ const [isGuestLoading, setIsGuestLoading] = useState(false);
const lastLoginMethod = authClient.getLastUsedLoginMethod();
const { data: config, isLoading: isConfigLoading } = useGetConfig();
@@ -43,6 +44,28 @@ function SignIn() {
}
};
+ const handleCustomOAuth = async () => {
+ setIsCustomOAuthLoading(true);
+ try {
+ const result = await authClient.signIn.oauth2({
+ providerId: "custom",
+ callbackURL: `${import.meta.env.VITE_CLIENT_URL}/dashboard`,
+ errorCallbackURL: `${import.meta.env.VITE_CLIENT_URL}/auth/sign-in`,
+ });
+ if (result.error) {
+ throw new Error(result.error.message);
+ }
+ toast.success("Signed in with OIDC");
+ navigate({ to: "/dashboard" });
+ } catch (error) {
+ toast.error(
+ error instanceof Error ? error.message : "Failed to sign in with OIDC",
+ );
+ } finally {
+ setIsCustomOAuthLoading(false);
+ }
+ };
+
const handleSignInGoogle = async () => {
setIsGoogleLoading(true);
try {
@@ -58,10 +81,12 @@ function SignIn() {
navigate({ to: "/dashboard" });
} catch (error) {
toast.error(
- error instanceof Error ? error.message : "Failed to sign in as guest",
+ error instanceof Error
+ ? error.message
+ : "Failed to sign in with Google",
);
} finally {
- setIsGuestLoading(false);
+ setIsGoogleLoading(false);
}
};
@@ -111,70 +136,116 @@ function SignIn() {
title="Welcome back"
subtitle="Enter your credentials to access your workspace"
>
- <div className="space-y-4 mt-6">
- <div className="flex flex-col gap-2">
- <div className="relative">
- {config?.hasGoogleSignIn && (
- <Button
- variant="outline"
- onClick={handleSignInGoogle}
- disabled={isGoogleLoading}
- className={cn(
- "w-full mb-2",
- lastLoginMethod === "google" && "!border-primary/50",
- )}
- >
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
- <title>Google</title>
- <path
- d="M12.48 10.92v3.28h7.84c-.24 1.84-.853 3.187-1.787 4.133-1.147 1.147-2.933 2.4-6.053 2.4-4.827 0-8.6-3.893-8.6-8.72s3.773-8.72 8.6-8.72c2.6 0 4.507 1.027 5.907 2.347l2.307-2.307C18.747 1.44 16.133 0 12.48 0 5.867 0 .307 5.387.307 12s5.56 12 12.173 12c3.573 0 6.267-1.173 8.373-3.36 2.16-2.16 2.84-5.213 2.84-7.667 0-.76-.053-1.467-.173-2.053H12.48z"
- fill="currentColor"
- />
- </svg>
- {isGoogleLoading ? "Signing in..." : "Continue with Google"}
- {lastLoginMethod === "google" && (
- <span className="absolute rounded-md -top-3 right-1 px-1.5 text-xs text-primary font-medium bg-sidebar border border-primary/50">
- Last used
- </span>
- )}
- </Button>
- )}
- {config?.hasGithubSignIn && (
+ <div className="mt-6">
+ {(config?.hasGoogleSignIn ||
+ config?.hasGithubSignIn ||
+ config?.hasCustomOAuth) && (
+ <>
+ <div className="space-y-3">
+ {config?.hasGoogleSignIn && (
+ <div className="relative">
+ <Button
+ variant="outline"
+ onClick={handleSignInGoogle}
+ disabled={isGoogleLoading}
+ className={cn(
+ "w-full",
+ lastLoginMethod === "google" && "border-primary/50!",
+ )}
+ >
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 24 24"
+ className="w-5 h-5 mr-2"
+ aria-label="Google"
+ >
+ <title>Google</title>
+ <path
+ d="M12.48 10.92v3.28h7.84c-.24 1.84-.853 3.187-1.787 4.133-1.147 1.147-2.933 2.4-6.053 2.4-4.827 0-8.6-3.893-8.6-8.72s3.773-8.72 8.6-8.72c2.6 0 4.507 1.027 5.907 2.347l2.307-2.307C18.747 1.44 16.133 0 12.48 0 5.867 0 .307 5.387.307 12s5.56 12 12.173 12c3.573 0 6.267-1.173 8.373-3.36 2.16-2.16 2.84-5.213 2.84-7.667 0-.76-.053-1.467-.173-2.053H12.48z"
+ fill="currentColor"
+ />
+ </svg>
+ {isGoogleLoading
+ ? "Signing in..."
+ : "Continue with Google"}
+ </Button>
+ {lastLoginMethod === "google" && (
+ <span className="absolute rounded-md -top-3 right-1 px-1.5 text-xs text-primary font-medium bg-sidebar border border-primary/50">
+ Last used
+ </span>
+ )}
+ </div>
+ )}
+
+ {config?.hasGithubSignIn && (
+ <div className="relative">
+ <Button
+ variant="outline"
+ onClick={handleSignInGithub}
+ disabled={isGithubLoading}
+ className={cn(
+ "w-full",
+ lastLoginMethod === "github" && "border-primary/50!",
+ )}
+ >
+ <Github className="w-5 h-5 mr-2" />
+ {isGithubLoading
+ ? "Signing in..."
+ : "Continue with GitHub"}
+ </Button>
+ {lastLoginMethod === "github" && (
+ <span className="absolute rounded-md -top-3 right-1 px-1.5 text-xs text-primary font-medium bg-sidebar border border-primary/50">
+ Last used
+ </span>
+ )}
+ </div>
+ )}
+
+ {config?.hasCustomOAuth && (
+ <div className="relative">
+ <Button
+ variant="outline"
+ onClick={handleCustomOAuth}
+ disabled={isCustomOAuthLoading}
+ className={cn(
+ "w-full",
+ lastLoginMethod === "custom" && "border-primary/50!",
+ )}
+ >
+ <KeyRound className="w-5 h-5 mr-2" />
+ {isCustomOAuthLoading
+ ? "Signing in..."
+ : "Continue with OIDC"}
+ </Button>
+ {lastLoginMethod === "custom" && (
+ <span className="absolute rounded-md -top-3 right-1 px-1.5 text-xs text-primary font-medium bg-sidebar border border-primary/50">
+ Last used
+ </span>
+ )}
+ </div>
+ )}
+
<Button
variant="outline"
- onClick={handleSignInGithub}
- disabled={isGithubLoading}
- className={cn(
- "w-full",
- lastLoginMethod === "github" && "!border-primary/50",
- )}
+ onClick={handleGuestAccess}
+ disabled={isGuestLoading}
+ className="w-full"
>
- <Github className="w-4 h-4 mr-2" />
- {isGithubLoading ? "Signing in..." : "Continue with GitHub"}
- {lastLoginMethod === "github" && (
- <span className="absolute rounded-md -top-3 right-1 px-1.5 text-xs text-primary font-medium bg-sidebar border border-primary/50">
- Last used
- </span>
- )}
+ <UserCheck className="w-4 h-4 mr-2" />
+ {isGuestLoading ? "Signing in..." : "Continue as guest"}
</Button>
- )}
- </div>
- <Button
- variant="outline"
- onClick={handleGuestAccess}
- disabled={isGuestLoading}
- className="w-full"
- size="sm"
- >
- <UserCheck className="w-4 h-4 mr-2" />
- {isGuestLoading ? "Signing in..." : "Continue as guest"}
- </Button>
- </div>
- <div className="flex items-center gap-4 my-4">
- <div className="flex-1 h-px bg-border" />
- <span className="text-sm text-muted-foreground">or</span>
- <div className="flex-1 h-px bg-border" />
- </div>
+ </div>
+
+ <div className="relative my-6">
+ <div className="absolute inset-0 flex items-center">
+ <div className="w-full border-t border-border" />
+ </div>
+ <div className="relative flex justify-center text-sm">
+ <span className="px-2 bg-card text-muted-foreground">or</span>
+ </div>
+ </div>
+ </>
+ )}
{config?.hasSmtp ? <MagicLinkSignInForm /> : <SignInForm />}
<AuthToggle
message="Don't have an account?"