@vibe-kit/auth
Universal OAuth authentication library for AI providers' MAX subscriptions. Currently supports Claude AI with Gemini, Grok, and ChatGPT Max coming soon.
Features
- MAX Subscription Access: Leverage your existing AI provider MAX subscriptions programmatically
- Multiple Providers: Claude AI (available), Gemini, Grok, ChatGPT Max (coming soon)
- Environment-Specific Builds: Separate Node.js and browser-compatible builds
- OAuth 2.0 + PKCE: Secure authentication with industry standards
- Token Management: Automatic token refresh and secure storage
- Browser & Node.js: Works in both web applications and server environments
Installation
npm install @vibe-kit/auth
Usage
Node.js Environment
For Node.js applications (CLI tools, servers, etc.), use the Node.js-specific import:
import { ClaudeAuth } from '@vibe-kit/auth/node';
const token = await ClaudeAuth.authenticate();
const isAuthenticated = await ClaudeAuth.isAuthenticated();
const accessToken = await ClaudeAuth.getValidToken();
const isValid = await ClaudeAuth.verify();
const status = await ClaudeAuth.getStatus();
await ClaudeAuth.logout();
Browser Environment
For browser/web applications, use the browser-safe import:
import { ClaudeWebAuth, LocalStorageTokenStorage } from '@vibe-kit/auth/browser';
const storage = new LocalStorageTokenStorage();
const auth = new ClaudeWebAuth(storage);
const { url, state, codeVerifier } = ClaudeWebAuth.createAuthorizationUrl();
window.open(url, '_blank');
const authCode = 'code123#state456';
const token = await auth.authenticate(authCode, codeVerifier, state);
const isAuthenticated = await auth.isAuthenticated();
const accessToken = await auth.getValidToken();
Using with AI Provider APIs
Once authenticated, use the access token with your MAX subscription to access AI APIs:
Claude AI (Available Now)
import { ClaudeAuth } from '@vibe-kit/auth/node';
let accessToken = await ClaudeAuth.getValidToken();
if (!accessToken) {
await ClaudeAuth.authenticate();
accessToken = await ClaudeAuth.getValidToken();
}
For browser applications:
import { ClaudeWebAuth, LocalStorageTokenStorage } from '@vibe-kit/auth/browser';
const storage = new LocalStorageTokenStorage();
const auth = new ClaudeWebAuth(storage);
const accessToken = await auth.getValidToken();
if (!accessToken) {
}
Token Import/Export (Node.js only)
import { ClaudeAuth } from '@vibe-kit/auth/node';
const envToken = await ClaudeAuth.exportToken('env');
const jsonToken = await ClaudeAuth.exportToken('json');
const fullToken = await ClaudeAuth.exportToken('full');
await ClaudeAuth.importToken({ fromEnv: true });
await ClaudeAuth.importToken({ fromFile: './token.json' });
await ClaudeAuth.importToken({ refreshToken: 'your-refresh-token' });
Types
interface OAuthToken {
access_token: string;
token_type: string;
expires_in?: number;
refresh_token?: string;
scope?: string;
created_at: number;
}
Storage Options
- MemoryTokenStorage: In-memory storage for server-side use
- LocalStorageTokenStorage: Browser localStorage (client-side only)
- CookieTokenStorage: Cookie-based storage for SSR applications
Security
- Tokens are stored with restricted file permissions (CLI)
- Automatic token refresh prevents expired token usage
- PKCE (Proof Key for Code Exchange) for secure OAuth flows
- State parameter validation prevents CSRF attacks
Environment Compatibility
- Node.js: Use
@vibe-kit/auth/node for full functionality including file system access and browser launching
- Browser: Use
@vibe-kit/auth/browser or default import for browser-safe functionality
- Universal: The default import provides browser-safe functionality that works everywhere
Why Use MAX Subscriptions?
Instead of paying per API call, leverage the subscriptions you already have:
- Cost Effective: Use your existing MAX subscriptions instead of pay-per-use APIs
- Higher Limits: MAX subscriptions often have higher rate limits and priority access
- Latest Models: Access to the newest and most capable models in each provider's lineup
- Consistent Experience: Same interface across different AI providers
Usage with Other Libraries
The auth package can be used with any Claude AI client library or direct API calls:
import { authenticate, getValidToken } from '@vibe-kit/auth/node';
import { ClaudeWebAuth } from '@vibe-kit/auth/browser';
Coming Soon
- Gemini Max: Access Google's most advanced AI models with your subscription
- Grok Max: Leverage xAI's premium models through your subscription
- ChatGPT Max: Use OpenAI's latest models with your existing subscription
With Official SDKs
import Anthropic from '@anthropic-ai/sdk';
import { ClaudeAuth } from '@vibe-kit/auth/node';
const accessToken = await ClaudeAuth.getValidToken();
const anthropic = new Anthropic({
apiKey: '',
authToken: accessToken,
});
const message = await anthropic.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1000,
messages: [{ role: 'user', content: 'Hello!' }]
});