Auth ↔ Connector Integration Guide
Tier C — Historical. This document is a point-in-time snapshot preserved for reference. For current architecture, see CANONICAL_PLATFORM_ARCHITECTURE.md.
IntegrateWise - Continuity Bridge: Complete Flow
The authentication system is seamlessly integrated with the One Connector to create a unified ecosystem experience.
Complete Flow
┌─────────────────────────────────────────────────────────────────┐
│ USER JOURNEY: From Identity to Ecosystem Connection │
└─────────────────────────────────────────────────────────────────┘
1. AUTHENTICATION (Identity)
└─→ User logs in via Clerk or Supabase
└─→ Auth provider confirms identity
└─→ Session/JWT issued
2. AUTHORIZATION (Permissions)
└─→ Check user role (admin/user)
└─→ Load permission scope
└─→ Determine connector access level
└─→ Create authorization context
3. APPROVAL (Confirmation)
└─→ Modal shows user information
└─→ Display granted permissions
└─→ List connected services
└─→ User approves connection
└─→ Generate connector approval token
4. CONNECTION (Integration)
└─→ Initialize One Connector
└─→ Connect to Spine API
└─→ Initialize MCP pool bridges
└─→ Send heartbeat to Spine
└─→ Services become available
5. OPERATION (Usage)
└─→ Application code uses getConnector()
└─→ Services route through One Connector
└─→ Health monitoring via Spine
└─→ All 4 provider layers functional
Implementation
1. Connector Approval Service
File: lib/auth/connector-approval.ts (304 lines)
Core functions:
getAuthorizationContext()- Get user's authorization levelrequestConnectorApproval()- Request ecosystem connection approvalconnectToEcosystem()- Establish One Connector connectioninitializeConnectorWithAuth()- Full flow orchestration
// Full initialization
const result = await initializeConnectorWithAuth()
if (result.success) {
// User is authenticated, authorized, and connected
// All ecosystem services available
}
2. Connector Approval Modal
File: components/auth/connector-approval-modal.tsx (200 lines)
Shows user:
- Their identity information
- Granted permissions
- Connected services
- Security notice
User can:
- Approve connection
- Cancel/dismiss
3. Connector Approval Hook
File: lib/auth/use-connector-approval.ts (203 lines)
Manages entire flow:
const {
showModal, // Modal visibility
loading, // Operation in progress
context, // User authorization context
approval, // Connector approval response
error, // Error message
isConnected, // Connection status
approve, // Function to approve
dismiss, // Function to dismiss modal
} = useConnectorApproval()
4. Auth Connector Provider
File: components/auth/auth-connector-provider.tsx (60 lines)
Wrapper component that:
- Checks connector status on mount
- Shows approval modal when needed
- Handles full flow automatically
- Wraps entire application
Usage
Setup in Root Layout
// app/layout.tsx
children,
}: {
children: React.ReactNode
}) {
return (
<html>
<body>
<ClerkProvider>
<AuthConnectorProvider>
{children}
</AuthConnectorProvider>
</ClerkProvider>
</body>
</html>
)
}
Automatic Flow
- User visits app
- Clerk provider handles authentication
- AuthConnectorProvider checks status
- If user not connected to ecosystem:
- Shows approval modal
- User approves
- One Connector initializes
- Modal closes
- User has full ecosystem access
Manual Control
// In any component
function MyComponent() {
const { isConnected, approve, disconnect } = useConnectorApproval()
if (!isConnected) {
return <p>Not connected to ecosystem</p>
}
return (
<div>
<p>Connected to ecosystem!</p>
<button onClick={disconnect}>Disconnect</button>
</div>
)
}
Authorization Context
interface ConnectorAuthorizationContext {
userId: string
tenantId: string
email: string
name: string
isAdmin: boolean
permissions: string[]
hasConnectorAccess: boolean
}
Default Permissions
Regular Users:
connector:read- Read connector statusconnector:execute- Execute through connectorauth:access- Access auth servicedatabase:read- Read database
Administrators:
- All regular user permissions +
connector:admin- Full connector controlauth:admin- Full auth controldatabase:write- Write to databaseai:execute- Execute AI servicesagent:execute- Execute agents
Approval Flow
interface ConnectorApprovalResponse {
approved: boolean
connectorId: string
connectedAt: number
expiresAt: number // 24 hours
permissions: string[]
error?: string
}
- Connector ID: Unique identifier for this connection
- Connected At: Timestamp when connection established
- Expires At: When approval expires (24 hours by default)
- Permissions: Scoped permissions for this session
Storage
Connection context stored in:
- SessionStorage:
connector_context - Cleared on: Logout, disconnect, window close
// Structure
{
userId: string
tenantId: string
connectorId: string
connectedAt: number
expiresAt: number
permissions: string[]
}
Lifecycle
On Login
- Auth provider authenticates user
- AuthConnectorProvider detects authenticated user
- Checks if connector already connected
- If not connected, shows approval modal
On Approval
- User reviews information
- Clicks "Approve & Connect"
- System:
- Generates connector ID
- Initializes One Connector
- Connects to Spine API
- Stores connection context
- Closes modal
On Use
- Application calls
getConnector() - Returns same connector instance (singleton)
- All services route through connector
- Spine monitors health
- Heartbeat sent every 30 seconds
On Logout
- Auth provider signs out user
- AuthConnectorProvider detects logout
- Clears connector context
- Disconnects from ecosystem
- User must re-authenticate and approve on next login
Security
Token Management
- Connector approval includes
expiresAt(24 hours) - Session storage cleared on tab close
- Service role keys never exposed to client
- Only necessary permissions scoped
Spine Integration
- All connections authenticated with Spine API key
- Heartbeat validates connection health
- Signals can revoke connector at any time
- Tenant isolation enforced
MCP Bridges
- Each service has its own credentials
- Never shared across connectors
- Per-service rate limiting
- Audit trail for all operations
Troubleshooting
Modal Not Showing
- Check if user is authenticated
- Verify
AuthConnectorProvideris in layout - Check browser console for errors
Approval Fails
- Check Spine API connectivity
- Verify user has connector access permission
- Check MCP pool status
Services Not Working After Connection
- Verify connector is connected:
useConnector().getStatus() - Check individual service health
- Verify environment variables are set
Environment Variables
# Required for Spine integration
SPINE_URL=https://spine.integratewise.ai
SPINE_API_KEY=...
# Required for MCP pool
MCP_URL=https://mcp.integratewise.ai
MCP_TOKEN=...
# Tenant info
INTEGRATEWISE_TENANT_ID=integratewise
INTEGRATEWISE_CLIENT_ID=app-frontend
# Auth provider (Clerk or Supabase)
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=...
CLERK_SECRET_KEY=...
# OR
NEXT_PUBLIC_SUPABASE_URL=...
NEXT_PUBLIC_SUPABASE_ANON_KEY=...
SUPABASE_SERVICE_ROLE_KEY=...
Testing
Test Both Auth Providers
// Test with Clerk
NEXT_PUBLIC_AUTH_PROVIDER=clerk
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_...
// Test with Supabase
NEXT_PUBLIC_AUTH_PROVIDER=supabase
NEXT_PUBLIC_SUPABASE_URL=https://...
Test Approval Flow
-
Start fresh:
- Open incognito window
- Clear session storage
- Verify no connector context
-
Login:
- Click login
- Authenticate with provider
- Should redirect back
-
Approval Modal:
- Should automatically appear
- Verify user info is correct
- Verify permissions list
-
Approve:
- Click "Approve & Connect"
- Should show connecting state
- Modal should close
- All services should be available
-
Refresh:
- Reload page
- Modal should NOT appear (already connected)
- Services should still work
-
Logout:
- Click logout
- Connection context cleared
- Session storage empty
- Modal should appear on next login
API Reference
getAuthorizationContext()
Returns user's authorization level and permissions
const context = await getAuthorizationContext()
requestConnectorApproval(context)
Request approval for connector connection
const approval = await requestConnectorApproval(context)
connectToEcosystem(context, approval)
Establish One Connector connection
const connected = await connectToEcosystem(context, approval)
initializeConnectorWithAuth()
Execute full flow (recommended)
const result = await initializeConnectorWithAuth()
if (result.success) {
// Connected
}
useConnectorApproval()
React hook for managing approval flow
const {
showModal,
context,
isConnected,
approve,
dismiss,
disconnect,
} = useConnectorApproval()
Summary
IntegrateWise - Continuity Bridge creates a seamless path from authentication to full ecosystem access:
- Identity - Know who the user is
- Authorization - Know what they can do
- Approval - User confirms connection
- Connection - One Connector initialized
- Operation - Full ecosystem access
All handled automatically through the AuthConnectorProvider wrapper with user-friendly approval modal.
Result: Single identity. Complete ecosystem. Infinite integration.