feat: add auth integration layer with CLI compatibility#3
Open
caffeinum wants to merge 19 commits into
Open
Conversation
- Implement OAuth PKCE authentication flow based on opencode implementation - Add ClaudeAuth and AnthropicAuth classes for programmatic auth - Store credentials securely in ~/.claude/credentials.json with 600 permissions - Automatic token refresh when expired - Complete auth example with interactive flow - Export auth functions: startAuth, isAuthenticated, getAccessToken, logout - Add comprehensive test coverage for auth functionality - Update README with detailed authentication documentation Resolves instantlyeasy#10 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> Co-authored-by: yolocode-ai <yolocodeai@users.noreply.github.com>
- renamed AuthAnthropic.access() to refresh() for clarity - removed storage dependency from refresh method - moved token storage logic to auth-example.ts - refresh now only handles token refresh, not storage 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- new example that doesn't use filesystem storage - outputs credentials directly to stdout - demonstrates token refresh functionality - useful for temporary auth or CI/CD environments 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
removed packages that are not actually used in the implementation: - crypto: using node's built-in crypto module - node-fetch: using native fetch api 🤖 generated with [claude code](https://claude.ai/code) co-authored-by: claude <noreply@anthropic.com>
- removed AuthFileStorage class for manual storage handling - kept zod validation schemas as exported helpers - updated auth-example.ts to use manual file operations - exported OAuthCredentials, validateCredentials, isValidCredentials 🤖 generated with [claude code](https://claude.ai/code) co-authored-by: claude <noreply@anthropic.com>
- created Auth class for high-level authentication management - added setupAuth() and quickAuth() helper functions - added withAuth() placeholder to QueryBuilder (full integration pending) - created comprehensive examples showing auth usage - added AUTH_INTEGRATION.md documentation the auth module provides: - automatic token refresh - flexible storage options (project-local or global) - interactive setup flow - programmatic auth management 🤖 generated with [claude code](https://claude.ai/code) co-authored-by: claude <noreply@anthropic.com>
- auth now defaults to ~/.claude/credentials.json for cli integration - added overwriteExisting option to prevent accidental credential overwrites - credentials are stored in claude cli format (wrapped in 'anthropic' key) - made integration explicit in documentation and console output - both sdk and cli now share the same authentication this means: authenticate once, use everywhere (sdk and cli) 🤖 generated with [claude code](https://claude.ai/code) co-authored-by: claude <noreply@anthropic.com>
d864cfc to
6b4daa7
Compare
b4b9e32 to
a468d24
Compare
- removed standalone setupAuth() and quickAuth() functions - withAuth() now handles authentication automatically when queries are executed - authentication prompts only appear when needed (lazy authentication) - simplified auth examples to show new integrated approach - maintains backward compatibility with Auth class for advanced use cases 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
- setupAuth() now returns { url, complete } for developer to handle UI
- removed automatic readline flow from SDK core
- withAuth() only validates credentials, doesn't prompt
- developer controls how to open URL (window.open, console.log, etc)
- developer controls how to get code (prompt, modal, readline, etc)
- updated examples to show different UI patterns
this gives full control to developers over the auth flow ui
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
the claude cli uses ~/.claude/.credentials.json (with dot prefix)
- logs full oauth exchange response - logs full oauth refresh response - logs requested scopes (including user:profile) - helps debug what user data is available from oauth
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a high-level authentication integration layer that seamlessly works with the Claude CLI by sharing credentials.
Key Features
🔐 Authentication Manager (
Authclass)~/.claude/credentials.jsonfor CLI integration🚀 Helper Functions
setupAuth()- Interactive authentication setupquickAuth()- One-line authenticationwithAuth()- Fluent API integration (placeholder for now)🔄 CLI Integration
~/.claude/credentials.jsonUsage
Implementation Details
Files Changed
src/auth/auth.ts- Authentication manager implementationsrc/fluent.ts- Added withAuth() placeholderexamples/auth-integrated.ts- Integration examplesAUTH_INTEGRATION.md- Complete documentationBuilt on top of #2
🤖 Generated with Claude Code