docs: pivot to Login Flow v2; add Astrolabe Cloud hosted offering
Replace the seven OAuth-to-Nextcloud docs (oauth-setup, quickstart-oauth, oauth-architecture, oauth-upstream-status, oauth-troubleshooting, jwt-oauth-reference, audience-validation-setup) with a single new docs/login-flow-v2.md. The deprecated flow required upstream user_oidc patches that were never merged; Login Flow v2 is the forward-looking multi-user mode (see ADR-022), and works with stock Nextcloud 16+. Rewrite docs/authentication.md and docs/auth-flows.md around three modes: Single-User BasicAuth, Multi-User BasicAuth pass-through, and Login Flow v2. Update README to add an Astrolabe Cloud (https://astrolabecloud.com) callout for users who prefer not to self-host, drop the OAuth deployment mode from the auth table, simplify the Docker block, and trim the Examples and Security sections. Sweep configuration.md, installation.md, troubleshooting.md, running.md, and semantic-search-architecture.md to replace links to the deleted docs and update deprecated mode names. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
19c4911954
commit
1306849353
+65
-220
@@ -1,252 +1,97 @@
|
||||
# Authentication
|
||||
|
||||
The Nextcloud MCP server supports two authentication modes for connecting to your Nextcloud instance.
|
||||
The Nextcloud MCP server authenticates to Nextcloud using **app-specific passwords** (HTTP Basic Auth). It supports three deployment modes that differ in how those credentials are sourced.
|
||||
|
||||
## Authentication Modes Comparison
|
||||
## Mode Comparison
|
||||
|
||||
| Mode | Status | Security | Use Case |
|
||||
|------|--------|----------|----------|
|
||||
| **OAuth2/OIDC** | ✅ Recommended | 🔒 High | Production deployments, multi-user scenarios |
|
||||
| **Basic Auth** | ⚠️ Legacy | ⚠️ Lower | Development, backward compatibility |
|
||||
| Mode | How credentials are obtained | Best for |
|
||||
|------|------------------------------|----------|
|
||||
| **Single-User (BasicAuth)** | App password in environment variables | Personal use, development, single-tenant deployments |
|
||||
| **Multi-User (BasicAuth pass-through)** | MCP client sends credentials in HTTP `Authorization` header | Internal multi-user setups where users manage their own Nextcloud credentials |
|
||||
| **Multi-User (Login Flow v2)** | Per-user app password obtained via Nextcloud's [Login Flow v2](https://docs.nextcloud.com/server/latest/developer_manual/client_apis/LoginFlow/index.html#login-flow-v2), stored encrypted | Hosted deployments, OAuth-based MCP clients (claude.ai, Astrolabe Cloud), production multi-user |
|
||||
|
||||
## OAuth2/OIDC (Recommended)
|
||||
> **OAuth-direct-to-Nextcloud is no longer supported.** It required upstream patches to `user_oidc` that were never merged. Login Flow v2 replaces it for multi-user deployments and works with stock Nextcloud 16+. See [ADR-022](ADR-022-deployment-mode-consolidation.md) for the rationale.
|
||||
|
||||
OAuth2/OIDC authentication provides secure, token-based authentication following modern security standards.
|
||||
## Single-User (BasicAuth)
|
||||
|
||||
### Architecture
|
||||
|
||||
The Nextcloud MCP Server acts as an **OAuth 2.0 Resource Server**, protecting access to Nextcloud resources:
|
||||
|
||||
```
|
||||
MCP Client ←→ MCP Server (Resource Server) ←→ Nextcloud (Authorization Server + APIs)
|
||||
OAuth Flow with PKCE Bearer Token Auth
|
||||
```
|
||||
|
||||
**Key Components**:
|
||||
- **MCP Server**: OAuth Resource Server (validates tokens, provides MCP tools)
|
||||
- **Nextcloud `oidc` app**: OAuth Authorization Server (issues tokens)
|
||||
- **Nextcloud `user_oidc` app**: Token validation middleware
|
||||
- **MCP Client**: Any MCP-compatible client (Claude, custom clients)
|
||||
|
||||
For detailed architecture, see [OAuth Architecture](oauth-architecture.md).
|
||||
|
||||
### Required Nextcloud Apps
|
||||
|
||||
OAuth authentication requires **two Nextcloud apps** to work together:
|
||||
|
||||
#### 1. `oidc` - OIDC Identity Provider
|
||||
**Purpose:** Makes Nextcloud an OAuth2/OIDC authorization server
|
||||
|
||||
**Provides:**
|
||||
- OAuth2 authorization endpoint (`/apps/oidc/authorize`)
|
||||
- Token endpoint (`/apps/oidc/token`)
|
||||
- User info endpoint (`/apps/oidc/userinfo`)
|
||||
- JWKS endpoint for token validation (`/apps/oidc/jwks`)
|
||||
- Dynamic client registration endpoint (`/apps/oidc/register`)
|
||||
|
||||
**Installation:** Available in Nextcloud App Store under "Security"
|
||||
|
||||
#### 2. `user_oidc` - OpenID Connect User Backend
|
||||
**Purpose:** Authenticates users and validates Bearer tokens
|
||||
|
||||
**Provides:**
|
||||
- Bearer token validation against the OIDC provider
|
||||
- User authentication via OIDC
|
||||
- Session management for authenticated users
|
||||
|
||||
**Installation:** Available in Nextcloud App Store under "Security"
|
||||
|
||||
**Important:** The `user_oidc` app requires a patch for Bearer token support on non-OCS endpoints (like Notes API). See [Upstream Status](oauth-upstream-status.md) for details.
|
||||
|
||||
### Benefits
|
||||
- **Zero-config deployment** via dynamic client registration
|
||||
- **No credential storage** in environment variables
|
||||
- **Per-user authentication** with access tokens
|
||||
- **Per-user permissions** - each user has their own Nextcloud client
|
||||
- **Automatic token validation** via Nextcloud OIDC userinfo endpoint
|
||||
- **Token caching** for performance (default: 1 hour TTL)
|
||||
- **PKCE required** for enhanced security (S256 code challenge)
|
||||
- **Secure by design** following OAuth 2.0 and OpenID Connect standards
|
||||
|
||||
### Current Implementation Limitations
|
||||
|
||||
> [!IMPORTANT]
|
||||
> **Tested Configuration:**
|
||||
> - ✅ Nextcloud `oidc` app (OIDC Identity Provider) + `user_oidc` app (OIDC User Backend)
|
||||
> - ✅ Nextcloud acting as its own identity provider (self-hosted OIDC)
|
||||
> - ✅ MCP server as OAuth Resource Server
|
||||
> - ✅ PKCE with S256 code challenge method
|
||||
>
|
||||
> **Not Tested:**
|
||||
> - ❌ External identity providers (Azure AD, Keycloak, Okta, etc.)
|
||||
> - ❌ Using `user_oidc` with external OIDC providers
|
||||
>
|
||||
> **Known Requirements:**
|
||||
> - 🔧 The `user_oidc` app requires a patch for Bearer token support on non-OCS endpoints (see [Upstream Status](oauth-upstream-status.md))
|
||||
> - ⏱️ Dynamic client registration credentials expire (default: 1 hour) - use pre-configured clients for production
|
||||
> - 🔐 PKCE must be advertised in OIDC discovery (see [Upstream Status](oauth-upstream-status.md))
|
||||
|
||||
### How OAuth Works
|
||||
|
||||
The MCP server implements the OAuth 2.0 Resource Server pattern:
|
||||
|
||||
**Phase 1: Authorization (OAuth Flow with PKCE)**
|
||||
1. MCP client connects and receives OAuth settings (issuer URL, scopes)
|
||||
2. Client initiates OAuth flow with PKCE (Proof Key for Code Exchange)
|
||||
3. User authenticates via browser to Nextcloud
|
||||
4. Nextcloud redirects back with authorization code
|
||||
5. Client exchanges code + code_verifier for access token
|
||||
|
||||
**Phase 2: API Access (Bearer Token Validation)**
|
||||
6. Client sends MCP requests with `Authorization: Bearer <token>` header
|
||||
7. MCP server validates token by calling Nextcloud's userinfo endpoint
|
||||
8. Server creates per-user NextcloudClient instance with the token
|
||||
9. All Nextcloud API requests use the user's Bearer token
|
||||
10. User-specific permissions and audit trails apply
|
||||
|
||||
This ensures:
|
||||
- Each user has their own authenticated session
|
||||
- Actions appear from the correct user in Nextcloud logs
|
||||
- Proper permission boundaries are maintained
|
||||
- No shared credentials between users
|
||||
|
||||
### See Also
|
||||
- [OAuth Quick Start](quickstart-oauth.md) - 5-minute setup for development
|
||||
- [OAuth Setup Guide](oauth-setup.md) - Detailed production setup
|
||||
- [OAuth Architecture](oauth-architecture.md) - Technical details
|
||||
- [Upstream Status](oauth-upstream-status.md) - Required patches and PR status
|
||||
- [OAuth Troubleshooting](oauth-troubleshooting.md) - OAuth-specific issues
|
||||
- [Configuration](configuration.md) - Environment variables
|
||||
|
||||
## Basic Authentication (Legacy)
|
||||
|
||||
Basic Authentication uses username and password credentials directly.
|
||||
|
||||
### Benefits
|
||||
- **Simple setup** with username/password
|
||||
- **Single-user** server instances
|
||||
- **Quick for development** and testing
|
||||
|
||||
### Limitations
|
||||
- **Credentials in environment** (less secure)
|
||||
- **Single user only** - all requests use the same account
|
||||
- **No audit trail** - all actions appear from the same user
|
||||
- **Maintained for compatibility** - will be deprecated in future versions
|
||||
|
||||
> [!WARNING]
|
||||
> **Security Notice:** Basic Authentication stores credentials in environment variables and is less secure than OAuth. It's maintained for backward compatibility only and may be deprecated in future versions. Use OAuth for production deployments.
|
||||
|
||||
### See Also
|
||||
- [Configuration](configuration.md#basic-authentication-legacy) - BasicAuth environment variables
|
||||
- [Running the Server](running.md#basicauth-mode-legacy) - BasicAuth examples
|
||||
|
||||
## Hybrid Authentication (Multi-User BasicAuth + OAuth)
|
||||
|
||||
When running in multi-user BasicAuth mode with `ENABLE_OFFLINE_ACCESS=true`, the server operates in **hybrid authentication mode**. This provides the simplicity of BasicAuth for normal operations with the security of OAuth for administrative functions.
|
||||
|
||||
### Authentication Domains
|
||||
|
||||
**MCP Operations** (Tools, Resources):
|
||||
- **Auth Method**: BasicAuth (HTTP Basic username/password)
|
||||
- **Characteristics**:
|
||||
- Stateless - no token storage
|
||||
- Simple configuration
|
||||
- Direct credential validation against Nextcloud
|
||||
- Credentials passed per-request in Authorization header
|
||||
- **Used For**: MCP tool calls from Claude, MCP client operations
|
||||
|
||||
**Management APIs** (Webhooks, Admin UI):
|
||||
- **Auth Method**: OAuth bearer tokens
|
||||
- **Characteristics**:
|
||||
- Per-user authorization via OAuth consent flow
|
||||
- Refresh tokens stored for background operations
|
||||
- Token validation via UnifiedTokenVerifier
|
||||
- Explicit user consent required
|
||||
- **Used For**: Astrolabe admin UI, webhook management, vector sync operations
|
||||
One set of credentials is configured in the environment and shared by all MCP clients. All Nextcloud requests are made as the same user.
|
||||
|
||||
### Configuration
|
||||
|
||||
```env
|
||||
# Enable multi-user BasicAuth
|
||||
ENABLE_MULTI_USER_BASIC_AUTH=true
|
||||
|
||||
# Enable hybrid mode (OAuth provisioning for management APIs)
|
||||
ENABLE_OFFLINE_ACCESS=true
|
||||
|
||||
# Enable background sync (required for hybrid mode currently)
|
||||
VECTOR_SYNC_ENABLED=true
|
||||
|
||||
# Encryption key for refresh token storage
|
||||
TOKEN_ENCRYPTION_KEY=<base64-encoded-key>
|
||||
|
||||
# Nextcloud connection
|
||||
NEXTCLOUD_HOST=https://cloud.example.com
|
||||
|
||||
# OAuth credentials (optional - uses DCR if not set)
|
||||
NEXTCLOUD_OIDC_CLIENT_ID=<client-id>
|
||||
NEXTCLOUD_OIDC_CLIENT_SECRET=<client-secret>
|
||||
```bash
|
||||
NEXTCLOUD_HOST=https://your.nextcloud.example.com
|
||||
NEXTCLOUD_USERNAME=your_username
|
||||
NEXTCLOUD_PASSWORD=your_app_password
|
||||
```
|
||||
|
||||
### OAuth Provisioning Flow
|
||||
|
||||
1. Admin opens Astrolabe admin settings in Nextcloud
|
||||
2. Clicks "Authorize" to enable webhook management
|
||||
3. Redirected to `/oauth/authorize-nextcloud` on MCP server
|
||||
4. MCP server redirects to Nextcloud OAuth consent page
|
||||
5. Admin grants OAuth consent (scopes: `openid`, `profile`, `offline_access`)
|
||||
6. Redirected back to `/oauth/callback` on MCP server
|
||||
7. MCP server stores refresh token (encrypted)
|
||||
8. Admin can now manage webhooks from Astrolabe UI
|
||||
|
||||
### Benefits
|
||||
|
||||
- **Simple MCP client setup**: Use BasicAuth (no OAuth complexity for end users)
|
||||
- **Secure background operations**: Webhooks use per-user OAuth tokens (no shared credentials)
|
||||
- **Explicit authorization**: Admins must explicitly grant OAuth consent for webhook operations
|
||||
- **Per-user isolation**: Each admin's webhook operations use their own refresh token
|
||||
Generate the app password in Nextcloud under **Settings → Security → Devices & sessions**. Don't use your login password.
|
||||
|
||||
### Trade-offs
|
||||
|
||||
- **Two auth systems**: More complex server configuration than pure BasicAuth or OAuth
|
||||
- **OAuth setup required**: Admins must complete OAuth flow before managing webhooks
|
||||
- **Token storage**: Requires database and encryption key for refresh tokens
|
||||
- ✅ Simplest setup; no persistent state
|
||||
- ✅ All MCP tools available (no scope enforcement — trusted environment)
|
||||
- ❌ No per-user identity; all actions appear from the same account in Nextcloud
|
||||
- ❌ Not suitable for shared deployments
|
||||
|
||||
### Comparison
|
||||
See [Configuration](configuration.md) for the full environment variable reference.
|
||||
|
||||
| Feature | Pure BasicAuth | Hybrid Mode | Pure OAuth |
|
||||
|---------|---------------|-------------|------------|
|
||||
| MCP Operations | BasicAuth | BasicAuth | OAuth Bearer Token |
|
||||
| Management API | N/A | OAuth Bearer Token | OAuth Bearer Token |
|
||||
| Webhook Operations | N/A | OAuth Refresh Token | OAuth Refresh Token |
|
||||
| MCP Client Setup | Simple | Simple | Complex (PKCE flow) |
|
||||
| Admin UI Auth | N/A | OAuth Consent | OAuth Login |
|
||||
| Token Storage | None | Refresh tokens only | All tokens |
|
||||
| Deployment Complexity | Low | Medium | High |
|
||||
## Multi-User (BasicAuth Pass-Through)
|
||||
|
||||
### Astrolabe User Setup (Hybrid Mode)
|
||||
Each MCP client sends its own credentials in an HTTP `Authorization: Basic` header. The server creates a per-request Nextcloud client from those credentials and never persists them.
|
||||
|
||||
For Astrolabe-specific user setup instructions in hybrid mode, see the [Astrolabe documentation](https://github.com/cbcoutinho/astrolabe/blob/master/docs/user-setup-hybrid-mode.md).
|
||||
### Configuration
|
||||
|
||||
### See Also
|
||||
- [OAuth Architecture](oauth-architecture.md) - Progressive Consent (Flow 2) details
|
||||
- [Configuration](configuration.md#enable_offline_access) - Hybrid mode configuration
|
||||
```bash
|
||||
NEXTCLOUD_HOST=https://your.nextcloud.example.com
|
||||
ENABLE_MULTI_USER_BASIC_AUTH=true
|
||||
```
|
||||
|
||||
`NEXTCLOUD_USERNAME` and `NEXTCLOUD_PASSWORD` must NOT be set in this mode.
|
||||
|
||||
### Trade-offs
|
||||
|
||||
- ✅ Stateless — no token storage required
|
||||
- ✅ Each user's actions are properly attributed in Nextcloud audit logs
|
||||
- ❌ Clients must handle Nextcloud credentials directly (credential exposure risk)
|
||||
- ❌ Not compatible with OAuth-based MCP clients (claude.ai, Astrolabe Cloud) without a credential bridge
|
||||
|
||||
## Multi-User (Login Flow v2)
|
||||
|
||||
The recommended mode for hosted and OAuth-based deployments. MCP clients authenticate to the MCP server via OAuth; the MCP server obtains a per-user app password from Nextcloud (via Login Flow v2) and uses HTTP Basic Auth to talk to Nextcloud APIs.
|
||||
|
||||
```
|
||||
MCP Client ──(OAuth, mcp:* scopes)──> MCP Server ──(Basic Auth, app password)──> Nextcloud
|
||||
```
|
||||
|
||||
The MCP server enforces `mcp:*` scopes at the application layer (defense-in-depth, since Nextcloud app passwords have no native scope support).
|
||||
|
||||
**See [Login Flow v2](login-flow-v2.md) for full setup, architecture, scope reference, and troubleshooting.**
|
||||
|
||||
## Mode Detection
|
||||
|
||||
The server automatically detects the authentication mode:
|
||||
The server detects the active mode from environment variables at startup:
|
||||
|
||||
- **OAuth mode**: When `NEXTCLOUD_USERNAME` and `NEXTCLOUD_PASSWORD` are NOT set
|
||||
- **BasicAuth mode**: When both username and password are provided
|
||||
| Env vars present | Detected mode |
|
||||
|------------------|---------------|
|
||||
| `NEXTCLOUD_USERNAME` + `NEXTCLOUD_PASSWORD` | Single-User (BasicAuth) |
|
||||
| `ENABLE_MULTI_USER_BASIC_AUTH=true` (no creds) | Multi-User (BasicAuth pass-through) |
|
||||
| `ENABLE_LOGIN_FLOW=true` (no creds) | Multi-User (Login Flow v2) |
|
||||
|
||||
You can also force a mode via CLI flag:
|
||||
|
||||
You can also force a specific mode using CLI flags:
|
||||
```bash
|
||||
# Force OAuth mode
|
||||
# Force Login Flow v2 / OAuth identity layer
|
||||
uv run nextcloud-mcp-server --oauth
|
||||
|
||||
# Force BasicAuth mode
|
||||
# Force BasicAuth
|
||||
uv run nextcloud-mcp-server --no-oauth
|
||||
```
|
||||
|
||||
## Switching Between Modes
|
||||
## See Also
|
||||
|
||||
See [Troubleshooting: Switching Between OAuth and BasicAuth](troubleshooting.md#switching-between-oauth-and-basicauth) for instructions.
|
||||
- [Login Flow v2](login-flow-v2.md) — multi-user setup details
|
||||
- [Configuration](configuration.md) — environment variable reference
|
||||
- [Authentication Flows](auth-flows.md) — sequence diagrams per mode
|
||||
- [Running the Server](running.md) — start, manage, troubleshoot
|
||||
- [Troubleshooting](troubleshooting.md) — common issues
|
||||
- [ADR-022](ADR-022-deployment-mode-consolidation.md) — design rationale for mode consolidation
|
||||
|
||||
Reference in New Issue
Block a user