import { ClaudeWebAuth, MemoryTokenStorage } from '@vibe-kit/auth';
// Frontend - Generate OAuth URL
const { url, state, codeVerifier } = ClaudeWebAuth.createAuthorizationUrl();
// Store for later use
sessionStorage.setItem('oauth_state', state);
sessionStorage.setItem('oauth_code_verifier', codeVerifier);
// Open Claude authentication in new tab
window.open(url, '_blank');
// After user copies the authentication code (format: code#state)
const authCode = "paste-authentication-code-here";
// Backend - Authenticate with the code
const storage = new MemoryTokenStorage(sessionId);
const auth = new ClaudeWebAuth(storage);
await auth.authenticate(authCode, codeVerifier, state);
// Use the token with VibeKit
const accessToken = await auth.getValidToken();
// Pass token as API key to VibeKit
const vibeKit = new VibeKit()
.withAgent({
type: "claude",
provider: "anthropic",
providerApiKey: accessToken, // Pass OAuth token as API key
model: "claude-sonnet-4-20250514",
})
.withSandbox(sandboxProvider);