Skip to content

chore: Cloud auth#213

Merged
phernandez merged 21 commits into
mainfrom
cloud-auth
Jul 8, 2025
Merged

chore: Cloud auth#213
phernandez merged 21 commits into
mainfrom
cloud-auth

Conversation

@phernandez

Copy link
Copy Markdown
Member

mege changes from cloud-auth branch

phernandez and others added 18 commits June 21, 2025 12:03
Signed-off-by: phernandez <paul@basicmachines.co>
Signed-off-by: phernandez <paul@basicmachines.co>
Signed-off-by: phernandez <paul@basicmachines.co>
- Override FastMCP's built-in OAuth endpoints with custom proxy routes
- Add dynamic client registration support via /api/oauth/register
- Proxy OAuth metadata and protected resource endpoints to basic-memory-cloud
- Use FastMCP's @mcp.custom_route decorator for proper integration
- MCP connection works successfully with OAuth flow in Inspector

Note: JWT authentication currently disabled - basic-memory-cloud returns
mock tokens instead of real JWTs. Auth will be re-enabled once cloud
service issues proper JWT tokens with correct aud/iss claims.

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

Co-Authored-By: Claude <noreply@anthropic.com>
- Create StytchBearerAuthProvider that supports URN-style issuer format
- Override FastMCP's bearer auth to handle Stytch's issuer format:
  "stytch.com/project-..." instead of requiring HTTP(S) URLs
- Update server to use custom auth provider with proper JWT validation
- Configure JWKS URI to validate tokens against Stytch's public keys
- Remove scope validation temporarily (scopes working but format differs)

✅ OAuth flow + JWT validation + MCP connection now works end-to-end
✅ Tokens properly validated against Stytch JWKS endpoint
✅ Audience and issuer validation working with URN format

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

Co-Authored-By: Claude <noreply@anthropic.com>
… auth server

- Fix OAuth flow by restoring basic-memory-cloud as authorization server
- Add registration_endpoint to basic-memory-cloud OAuth metadata pointing to Stytch
- Configure basic-memory as protected resource server only
- Remove OAuth proxy routes from basic-memory (no longer needed)
- Update environment variables to point authorization_servers to basic-memory-cloud
- Move auth provider to src/basic_memory/mcp/http/auth.py with proper settings
- Update AUTH_JWT.md documentation to reflect correct architecture

The OAuth flow now works properly:
1. MCP Inspector discovers protected resource at basic-memory:8000
2. Follows authorization_servers to basic-memory-cloud:3000
3. Uses Stytch registration endpoint for dynamic client registration
4. Completes OAuth flow via basic-memory-cloud with Stytch authentication
5. Uses JWT tokens to access basic-memory MCP endpoints

This restores the working state from yesterday where basic-memory-cloud
handles OAuth/authentication and basic-memory handles MCP API/authorization.

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

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: phernandez <paul@basicmachines.co>
Signed-off-by: phernandez <paul@basicmachines.co>
Signed-off-by: phernandez <paul@basicmachines.co>
…ration

- Add OAuth authorization server metadata endpoint with registration support
- Override MCP's hardcoded OAuth metadata to include public client support
- Implement Stytch dynamic client registration endpoint generation
- Add comprehensive OAuth 2.1 + PKCE support for Claude Desktop authentication
- Configure Fly.io proxy middleware for HTTPS handling in cloud deployments

Key changes:
- OAuth metadata now includes `registration_endpoint` pointing to Stytch
- Support both confidential (`client_secret_post`) and public (`none`) OAuth clients
- Add custom middleware for /mcp path handling without redirects
- Debug OAuth script for testing authentication flows

This enables seamless Claude Desktop authentication with Basic Memory Cloud
instances via Stytch magic link authentication and proper OAuth 2.1 flows.

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

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: phernandez <paul@basicmachines.co>
Signed-off-by: phernandez <paul@basicmachines.co>
Signed-off-by: phernandez <paul@basicmachines.co>
Fixed multiple issues that were causing 13+ integration tests to fail:

1. **Remove legacy migration service**: Deleted migration service that was
   incorrectly removing .basic-memory config directories during tests

2. **Fix critical ConfigManager bugs**: Corrected get_project method that had
   multiple bugs including wrong variable names and undefined references

3. **Fix test syntax error**: Corrected test assertion to use proper
   content[0].text accessor

4. **Improve move_note cross-project detection**: Removed overly aggressive
   keyword-based detection that was causing false positives with legitimate
   paths like "projects/2025/q2/work/nested-note.md"

5. **Clean up duplicate tests**: Removed redundant cross-project detection test

All 103 integration tests now pass successfully.

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

Co-Authored-By: Claude <noreply@anthropic.com>
- Add api_url field to BasicMemoryConfig for connecting to remote Basic Memory APIs
- Refactor async_client.py to conditionally create HTTP or ASGI transport based on config
- Add logging for client creation (info for remote, debug for local)
- Add basic test coverage for both local ASGI and remote HTTP client creation
- When api_url is set, MCP tools will connect to remote API instead of local ASGI transport

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

Co-Authored-By: Claude <noreply@anthropic.com>
@phernandez phernandez changed the title Cloud auth chore: Cloud auth Jul 8, 2025
Signed-off-by: phernandez <paul@basicmachines.co>
Signed-off-by: phernandez <paul@basicmachines.co>
Signed-off-by: phernandez <paul@basicmachines.co>
@phernandez phernandez merged commit 473f70c into main Jul 8, 2025
8 checks passed
@phernandez phernandez deleted the cloud-auth branch July 8, 2025 02:08
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.

1 participant