entelix_auth_claude_code/config.rs
1//! Configuration values for [`super::ClaudeCodeOAuthProvider`].
2
3use std::time::Duration;
4
5/// Canonical Claude.ai OAuth token endpoint.
6pub const DEFAULT_TOKEN_URL: &str = "https://console.anthropic.com/v1/oauth/token";
7
8/// Anthropic-beta capability gate the `claude` CLI sets on every
9/// request.
10///
11/// Operators using [`super::ClaudeCodeOAuthProvider`] must also pass
12/// this value through
13/// [`entelix_core::ir::AnthropicExt::with_betas`] so the codec emits
14/// the matching header — the credential surface and the codec
15/// surface stay independent (single responsibility).
16///
17/// **Source of truth**: Anthropic's beta-header registry under
18/// <https://platform.claude.com/docs/en/release-notes/overview>.
19/// Anthropic versions beta capabilities by date stamp; if Claude
20/// Code rolls a successor (e.g. `claude-code-2026XXXX`) bump this
21/// constant in lockstep — the OAuth refresh flow stays unchanged.
22pub const CLAUDE_CODE_BETA: &str = "claude-code-20250219";
23
24/// Default refresh-call HTTP timeout.
25pub const DEFAULT_REFRESH_TIMEOUT: Duration = Duration::from_secs(30);
26
27/// Configuration for [`super::ClaudeCodeOAuthProvider`].
28#[derive(Clone, Debug)]
29#[non_exhaustive]
30pub struct ClaudeCodeOAuthConfig {
31 /// OAuth2 token endpoint URL. Defaults to
32 /// [`DEFAULT_TOKEN_URL`].
33 pub token_url: String,
34 /// Optional OAuth client id sent with the `refresh_token`
35 /// grant. The `claude` CLI omits this; supply a value only
36 /// if your refresh-token policy requires one.
37 pub client_id: Option<String>,
38 /// HTTP timeout applied to refresh requests.
39 pub refresh_timeout: Duration,
40}
41
42impl Default for ClaudeCodeOAuthConfig {
43 fn default() -> Self {
44 Self {
45 token_url: DEFAULT_TOKEN_URL.to_owned(),
46 client_id: None,
47 refresh_timeout: DEFAULT_REFRESH_TIMEOUT,
48 }
49 }
50}
51
52impl ClaudeCodeOAuthConfig {
53 /// Construct an empty config (`Self::default`).
54 #[must_use]
55 pub fn new() -> Self {
56 Self::default()
57 }
58
59 /// Override the token endpoint URL — useful for staging
60 /// environments or test mocks.
61 #[must_use]
62 pub fn with_token_url(mut self, url: impl Into<String>) -> Self {
63 self.token_url = url.into();
64 self
65 }
66
67 /// Set the OAuth client id sent with the refresh grant.
68 #[must_use]
69 pub fn with_client_id(mut self, client_id: impl Into<String>) -> Self {
70 self.client_id = Some(client_id.into());
71 self
72 }
73
74 /// Override the refresh-call HTTP timeout.
75 #[must_use]
76 pub const fn with_refresh_timeout(mut self, timeout: Duration) -> Self {
77 self.refresh_timeout = timeout;
78 self
79 }
80}