1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//! # anthropic-auth
//!
//! A Rust library for Anthropic/Claude OAuth 2.0 authentication with PKCE support.
//!
//! This library provides both synchronous (blocking) and asynchronous (runtime-agnostic)
//! APIs for authenticating with Anthropic's OAuth 2.0 endpoints.
//!
//! ## Features
//!
//! - **Sync API** (default): Blocking operations, no async runtime required
//! - **Async API** (optional): Runtime-agnostic async operations
//! - **PKCE Support**: Secure PKCE (SHA-256) authentication flow with separate CSRF state tokens
//! - **Two OAuth Modes**: Max (subscription) and Console (API key creation)
//! - **Configurable**: Custom client IDs, redirect URIs
//! - **Browser Integration**: Auto-open browser for authorization (default)
//! - **Callback Server**: Local server for automatic callback handling (optional, requires tokio)
//! - **API Key Creation**: Create API keys via Console OAuth
//! - **Token Validation**: Built-in validation for tokens and parameters
//!
//! ## Choosing Between Sync and Async
//!
//! - Use [`OAuthClient`] (sync) if you're building a CLI tool or simple application without async
//! - Use [`AsyncOAuthClient`] (async) if you're building a web server or async application
//!
//! ## Quick Start (Sync API)
//!
//! ```no_run
//! use anthropic_auth::{OAuthClient, OAuthConfig, OAuthMode};
//!
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let client = OAuthClient::new(OAuthConfig::default())?;
//! let flow = client.start_flow(OAuthMode::Max)?;
//!
//! println!("Visit: {}", flow.authorization_url);
//! // User authorizes and receives response in format: "code#state"
//! let response = "code123#state456";
//!
//! // Library automatically parses and validates the state
//! let tokens = client.exchange_code(response, &flow.state, &flow.verifier)?;
//! println!("Got tokens!");
//! Ok(())
//! }
//! ```
//!
//! ## Quick Start (Async API)
//!
//! ```no_run
//! # #[cfg(feature = "async")]
//! # {
//! use anthropic_auth::{AsyncOAuthClient, OAuthConfig, OAuthMode};
//!
//! # #[tokio::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let client = AsyncOAuthClient::new(OAuthConfig::default())?;
//! let flow = client.start_flow(OAuthMode::Max)?;
//!
//! println!("Visit: {}", flow.authorization_url);
//! // User authorizes and receives response in format: "code#state"
//! let response = "code123#state456";
//!
//! // Library automatically parses and validates the state
//! let tokens = client.exchange_code(response, &flow.state, &flow.verifier).await?;
//! println!("Got tokens!");
//! # Ok(())
//! # }
//! # }
//! ```
// Public API exports
pub use ;
pub use ;
pub use OAuthClient;
pub use AsyncOAuthClient;
pub use open_browser;
pub use ;