From e3ef67514e1a5ff7d4d086cb94567abe384b9578 Mon Sep 17 00:00:00 2001 From: jonthan kabuya Date: Wed, 31 Dec 2025 14:06:54 +0200 Subject: [PATCH 01/60] feat: add SSO SAML authentication feature - Implement SAML-based Single Sign-On via identity providers (Okta, Azure AD, Google) - Add SSO provider management and configuration endpoints - Include domain-to-provider mappings for SSO detection - Automatic enrollment of SSO-authenticated users to organizations - Comprehensive audit logging for SSO events - DNS domain verification support (prepared for future enhancement) - Mock SSO callback for local development and testing - Frontend SSO login flow and detection composable - Independent from domain-based auto-join feature Tables: - org_saml_connections: SAML provider configuration per organization - saml_domain_mappings: Maps email domains to SSO providers - sso_audit_logs: Audit trail for SSO authentication events Endpoints: - POST /private/sso/configure - Add SAML connection - PUT /private/sso/update - Update SAML configuration - DELETE /private/sso/remove - Remove SSO provider - GET /private/sso/status - View SSO configuration - POST /private/sso/test - Test SAML connection - GET /sso-login - SSO login page Frontend: - useSSODetection composable for SSO detection - /sso-login page for SSO authentication - Organization SSO settings page Migration: - Creates SSO tables and domain mapping infrastructure - Adds auto_enroll_sso_user function for SSO users - Adds lookup_sso_provider_by_domain for SSO detection - Includes audit logging and RLS policies --- PR_CHECKLIST.md | 290 ++++ SSO_IMPLEMENTATION_SUMMARY.md | 463 +++++ SSO_TESTING_GUIDE.md | 406 +++++ docs/MOCK_SSO_TESTING.md | 210 +++ docs/sso-production.md | 574 +++++++ docs/sso-setup.md | 534 ++++++ playwright/e2e/sso.spec.ts | 266 +++ restart-auth-with-saml-v2.sh | 98 ++ restart-auth-with-saml.sh | 83 + src/composables/useSSODetection.ts | 191 +++ src/pages/settings/organization/sso.vue | 1194 +++++++++++++ src/pages/sso-login.vue | 165 ++ .../_backend/private/sso_configure.ts | 1 + .../_backend/private/sso_management.ts | 1497 +++++++++++++++++ .../functions/_backend/private/sso_remove.ts | 96 ++ .../functions/_backend/private/sso_status.ts | 98 ++ .../functions/_backend/private/sso_test.ts | 463 +++++ .../functions/_backend/private/sso_update.ts | 99 ++ supabase/functions/mock-sso-callback/index.ts | 404 +++++ .../20251224033604_add_sso_login_trigger.sql | 77 + ...0251226121026_fix_sso_domain_auto_join.sql | 77 + .../20251226121702_enforce_sso_signup.sql | 101 ++ ...20251226133424_fix_sso_lookup_function.sql | 46 + ...251226182000_fix_sso_auto_join_trigger.sql | 142 ++ ...10100_allow_sso_metadata_signup_bypass.sql | 95 ++ ...1231000002_add_sso_saml_authentication.sql | 580 +++++++ temp-sso-trace.ts | 51 + tests/sso-management.test.ts | 1207 +++++++++++++ 28 files changed, 9508 insertions(+) create mode 100644 PR_CHECKLIST.md create mode 100644 SSO_IMPLEMENTATION_SUMMARY.md create mode 100644 SSO_TESTING_GUIDE.md create mode 100644 docs/MOCK_SSO_TESTING.md create mode 100644 docs/sso-production.md create mode 100644 docs/sso-setup.md create mode 100644 playwright/e2e/sso.spec.ts create mode 100755 restart-auth-with-saml-v2.sh create mode 100755 restart-auth-with-saml.sh create mode 100644 src/composables/useSSODetection.ts create mode 100644 src/pages/settings/organization/sso.vue create mode 100644 src/pages/sso-login.vue create mode 100644 supabase/functions/_backend/private/sso_configure.ts create mode 100644 supabase/functions/_backend/private/sso_management.ts create mode 100644 supabase/functions/_backend/private/sso_remove.ts create mode 100644 supabase/functions/_backend/private/sso_status.ts create mode 100644 supabase/functions/_backend/private/sso_test.ts create mode 100644 supabase/functions/_backend/private/sso_update.ts create mode 100644 supabase/functions/mock-sso-callback/index.ts create mode 100644 supabase/migrations/20251224033604_add_sso_login_trigger.sql create mode 100644 supabase/migrations/20251226121026_fix_sso_domain_auto_join.sql create mode 100644 supabase/migrations/20251226121702_enforce_sso_signup.sql create mode 100644 supabase/migrations/20251226133424_fix_sso_lookup_function.sql create mode 100644 supabase/migrations/20251226182000_fix_sso_auto_join_trigger.sql create mode 100644 supabase/migrations/20251227010100_allow_sso_metadata_signup_bypass.sql create mode 100644 supabase/migrations/20251231000002_add_sso_saml_authentication.sql create mode 100644 temp-sso-trace.ts create mode 100644 tests/sso-management.test.ts diff --git a/PR_CHECKLIST.md b/PR_CHECKLIST.md new file mode 100644 index 0000000000..cba8715437 --- /dev/null +++ b/PR_CHECKLIST.md @@ -0,0 +1,290 @@ +# Pull Request Quality Checklist + +This checklist ensures your PRs meet Capgo's high standards. Use this before submitting ANY pull request. + +--- + +## ๐Ÿ“‹ Pre-Submission Checklist + +### โœ… Code Quality (CRITICAL - Always Check) + +- [ ] **Ran `bun lint:fix`** - Auto-fixes all linting issues (MANDATORY before commit) +- [ ] **Ran `bun lint`** - Verified no linting errors remain +- [ ] **Ran `bun lint:backend`** - If backend files were modified +- [ ] **Ran `bun typecheck`** - TypeScript type checking passes +- [ ] Code follows Vue 3 Composition API with ` + +