Skip to content

Comments

Add authentication system for Live Components#57

Merged
MarcosBrendonDePaula merged 8 commits intomainfrom
claude/live-component-auth-setup-3Rm9o
Feb 12, 2026
Merged

Add authentication system for Live Components#57
MarcosBrendonDePaula merged 8 commits intomainfrom
claude/live-component-auth-setup-3Rm9o

Conversation

@MarcosBrendonDePaula
Copy link
Collaborator

Summary

This PR introduces a comprehensive authentication and authorization system for Live Components, enabling developers to protect components and actions with role-based access control (RBAC) and permission-based authorization.

Key Changes

Core Authentication System

  • LiveAuthContext (core/server/live/auth/LiveAuthContext.ts): Implements authenticated and anonymous contexts with helpers for role/permission checking
  • LiveAuthManager (core/server/live/auth/LiveAuthManager.ts): Singleton manager for registering auth providers and authorizing component access and action execution
  • Auth Types (core/server/live/auth/types.ts): Defines interfaces for credentials, users, providers, and component/action auth configurations

Component Integration

  • Component-level auth: static auth: LiveComponentAuth declares component-level requirements (required, roles, permissions)
  • Action-level auth: static actionAuth: LiveActionAuthMap declares per-action authorization rules
  • $auth proxy: Components access authentication context via this.$auth with methods like hasRole(), hasPermission(), etc.
  • ComponentRegistry: Enhanced to check authorization before mounting components and executing actions

WebSocket & Client Integration

  • WebSocket plugin: Authenticates connections from query parameters and stores auth context in socket data
  • LiveComponentsProvider: Added authenticate() method and authenticated state for client-side auth management
  • LiveAuthOptions: New interface for passing credentials during connection

Example Implementations

  • LiveAdminPanel (app/server/live/LiveAdminPanel.ts): Demonstrates component-level auth (requires admin role) and action-level auth (deleteUser requires 'users.delete' permission)
  • LiveProtectedChat (app/server/live/LiveProtectedChat.ts): Shows basic auth requirement and per-action permissions
  • AuthDemo (app/client/src/live/AuthDemo.tsx): React client example showing public/protected components and auth flows
  • JWTAuthProvider (app/server/auth/JWTAuthProvider.example.ts): Example custom provider implementation
  • CryptoAuthLiveProvider (plugins/crypto-auth/server/CryptoAuthLiveProvider.ts): Adapter integrating crypto-auth plugin with Live Components

Comprehensive Test Suite

  • live-component-auth.test.ts: 635 lines of unit tests covering:
    • AuthenticatedContext and AnonymousContext behavior
    • Provider registration and authentication flows
    • Component and action authorization logic
    • Role and permission checking (OR/AND semantics)
    • Error handling and edge cases

Implementation Details

  • Role logic: OR semantics (user needs ANY of the required roles)
  • Permission logic: AND semantics (user needs ALL required permissions)
  • Anonymous fallback: Unauthenticated connections receive ANONYMOUS_CONTEXT singleton
  • Provider extensibility: Custom providers implement LiveAuthProvider interface for any auth strategy
  • Backward compatible: Components without auth config remain public and accessible to all users

https://claude.ai/code/session_0137gRBGeVfVpxJpCS63dVKQ

claude and others added 8 commits February 12, 2026 17:35
Introduce a complete authentication infrastructure for Live Components,
allowing developers to declaratively protect components and actions with
roles and permissions via static properties.

Key additions:
- LiveAuthProvider interface for pluggable auth strategies (JWT, crypto, session)
- LiveAuthManager singleton for provider registration and authorization checks
- LiveAuthContext with role/permission helpers available via this.$auth
- Static auth config on components (static auth / static actionAuth)
- WebSocket AUTH message type + query param token support
- Auth checks on component mount, rehydration, and action execution
- CryptoAuthLiveProvider adapter bridging existing crypto-auth plugin
- Client-side auth support in LiveComponentsProvider (auth prop + authenticate())
- Example LiveProtectedChat demonstrating the auth system

https://claude.ai/code/session_0137gRBGeVfVpxJpCS63dVKQ
Tests cover:
- AuthenticatedContext and AnonymousContext (role/permission helpers)
- LiveAuthManager (provider registration, authentication, authorization)
- LiveComponent $auth integration (context injection, static config)
- Component mount authorization (required, roles, permissions)
- Action-level authorization (per-action roles/permissions)
- Room authorization

https://claude.ai/code/session_0137gRBGeVfVpxJpCS63dVKQ
- Export LiveAuthOptions from core/client/index.ts
- Add $authenticated to LiveComponentProxy interface and proxy getter
- Add $authenticated to RESERVED_PROPS and ownKeys
- Filter setAuthContext from ExtractActions (defensive guard)
- Wire wsAuthenticated from LiveComponentsProvider into useMemo deps

Client-side devs can now:
  component.$authenticated  // boolean - typed
  useLiveComponents().authenticated  // boolean - typed
  useLiveComponents().authenticate({ token }) // Promise<boolean> - typed
  <LiveComponentsProvider auth={{ token }}>  // typed prop

https://claude.ai/code/session_0137gRBGeVfVpxJpCS63dVKQ
…ider)

- LiveAdminPanel: server component with static auth, actionAuth, $auth usage
- AuthDemo.tsx: client demo showing public vs protected components,
  dynamic login via authenticate(), $authenticated in proxy
- JWTAuthProvider.example.ts: how to create a custom LiveAuthProvider

https://claude.ai/code/session_0137gRBGeVfVpxJpCS63dVKQ
- Add DevAuthProvider with simple tokens (admin-token, user-token, mod-token)
- Add /auth route with interactive auth demo
- Update LiveAuthManager to try all providers (fallback chain)
- Fix auth flow to re-mount components after authentication
- Add navigation link to Auth demo page

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add authDenied tracking to detect AUTH_DENIED failures
- Auto retry mount when wsAuthenticated changes from false to true
- Simplify AuthDemo by removing manual key/re-render logic
- Fix infinite loop by properly setting mountFailed on all errors

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Create LLMD/resources/live-auth.md with complete auth guide
- Document static auth, actionAuth, $auth helper
- Document client-side authentication flow
- Document custom auth providers
- Update INDEX.md with Live Auth link
- Update live-components.md with related links

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add authentication subsection under Live Components
- Show server-side auth config (static auth, actionAuth)
- Show client-side authenticate() usage
- Add Live Auth to documentation links
- Add /auth route to frontend routes table
- Update features list with Auth System

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@MarcosBrendonDePaula MarcosBrendonDePaula merged commit 51e6aa7 into main Feb 12, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants