claude_codex/providers/grok/auth/
token_store.rs1use serde::{Deserialize, Serialize};
2
3use crate::auth::{AuthStorage, FileAuthStore};
4use crate::paths;
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
7#[serde(deny_unknown_fields)]
8pub struct StoredAuth {
9 pub access: String,
10 pub refresh: String,
11 pub expires_at_ms: u64,
12 pub issuer: String,
13 pub client_id: String,
14}
15
16pub struct GrokTokenStore<S: AuthStorage<StoredAuth>> {
17 store: S,
18}
19
20impl<S: AuthStorage<StoredAuth>> GrokTokenStore<S> {
21 pub fn new(store: S) -> Self {
22 Self { store }
23 }
24 pub fn load_auth(&self) -> anyhow::Result<Option<StoredAuth>> {
25 self.store.load()
26 }
27 pub fn save_auth(&self, auth: StoredAuth) -> anyhow::Result<()> {
28 self.store.save(auth)
29 }
30 pub fn clear_auth(&self) -> anyhow::Result<()> {
31 self.store.clear()
32 }
33 pub fn auth_path(&self) -> String {
34 self.store.path()
35 }
36}
37
38pub fn file_store() -> GrokTokenStore<FileAuthStore<StoredAuth>> {
39 let primary = paths::provider_auth_file("grok");
40 let legacy = paths::provider_legacy_auth_file("grok");
41 GrokTokenStore::new(FileAuthStore::new(
42 primary.to_string_lossy().into_owned(),
43 legacy.to_string_lossy().into_owned(),
44 ))
45}