artifactize-provider 0.27.1

Managed credentials, model discovery and direct HTTP turns for Artifactize.
Documentation
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
//! Codex (ChatGPT) sign-in: artifactize's own OAuth tokens in provider-owned private storage,
//! or a Codex auth file that artifactize only reads.
//!
//! The protocol follows Pi's `openai-codex` provider (pi-mono
//! `packages/ai/src/auth/oauth/openai-codex.ts`): the Codex public OAuth client, PKCE
//! with S256, the `localhost:1455` callback or a pasted redirect URL, the
//! authorization-code and refresh-token grants, and the ChatGPT account ID from the
//! access token's `https://api.openai.com/auth` claim. Revocation on logout follows the
//! Codex CLI (`codex-rs/login/src/auth/revoke.rs`). Callers must never print or log a
//! token.

use std::{
    path::{Path, PathBuf},
    time::Duration,
};

use base64::{
    Engine,
    engine::general_purpose::{URL_SAFE, URL_SAFE_NO_PAD},
};
use reqwest::Url;
use serde::{Deserialize, Serialize};
use serde_json::json;
mod auth_file;
mod callback;
mod interactive;
pub(crate) use auth_file::import_stamp;
use auth_file::{AuthFileError, FileToken, read_auth_file_at};
#[cfg(test)]
use interactive::*;
pub use interactive::{CALLBACK_PATH, CALLBACK_PORT, CallbackPort, Prompt, login_with};
#[cfg(test)]
use sha2::{Digest, Sha256};
#[cfg(test)]
use std::{collections::BTreeMap, ffi::OsStr};
#[cfg(test)]
use tokio::sync::oneshot;
mod timestamp;
use callback::Callback;
pub use timestamp::Timestamp;

use super::storage::{Location, MAX_CREDENTIAL_BYTES, Storage};

/// The Codex CLI's public OAuth client, which Pi's provider uses too.
pub const CLIENT_ID: &str = "app_EMoamEEZ73f0CkXaXp7hrann";
const AUTH_ROOT: &str = "https://auth.openai.com";
/// A loopback test endpoint replacing the sign-in root, beside the backends' own.
pub const AUTH_URL_VARIABLE: &str = "ARTIFACTIZE_CODEX_AUTH_URL";
/// A Codex auth file (for example `~/.codex/auth.json`) to read instead of
/// artifactize's own tokens. It is never written, copied or refreshed.
pub const AUTH_FILE_VARIABLE: &str = "ARTIFACTIZE_CODEX_AUTH_FILE";
/// The `originator` that sign-in and every Codex request name.
pub const ORIGINATOR: &str = "artifactize";
#[cfg(test)]
const CLAIM: &str = "https://api.openai.com/auth";
pub(crate) const CREDENTIALS: &str = "codex.json";
const LOCK: &str = "codex";
/// Refresh this many seconds before expiry, as the Codex CLI's refresh window does.
const REFRESH_MARGIN: Duration = Duration::from_secs(300);
/// Bound individual token-exchange HTTP calls independently of the interactive login wait.
const AUTH_HTTP_TIMEOUT: Duration = Duration::from_secs(30);
/// Best-effort logout should finish sooner than an ordinary token exchange.
const REVOCATION_TIMEOUT: Duration = Duration::from_secs(10);
const LOGIN_REQUIRED: &str =
    "Codex is not signed in; run `artifactize login codex` or set ARTIFACTIZE_CODEX_AUTH_FILE.";

#[derive(Deserialize, Serialize)]
struct Credentials {
    access_token: String,
    refresh_token: String,
    account_id: crate::names::CodexAccountId,
    #[serde(with = "timestamp::seconds")]
    expires_at: Timestamp,
    #[serde(with = "timestamp::seconds")]
    saved_at: Timestamp,
}

impl Credentials {
    fn values(&self) -> [&str; 2] {
        [&self.access_token, &self.refresh_token]
    }

    fn publish(&self, storage: &Storage) -> Result<(), String> {
        crate::secret::history::publish(storage, self.values())
    }
}

fn read_stored(storage: &Storage) -> Result<Option<Credentials>, String> {
    storage.read(CREDENTIALS)
}

/// Why no token is available. A transient failure (the token endpoint unreachable or
/// failing with 429 or 5xx) may succeed on a retry; any other means signing in again.
#[derive(Debug)]
pub struct TokenError {
    pub transient: bool,
    pub message: String,
}

impl From<String> for TokenError {
    fn from(message: String) -> Self {
        Self {
            transient: false,
            message,
        }
    }
}

impl From<&str> for TokenError {
    fn from(message: &str) -> Self {
        message.to_owned().into()
    }
}

/// A bearer token and the ChatGPT account it belongs to. Never printed or logged.
pub(crate) struct Token {
    pub access_token: String,
    pub account_id: crate::names::CodexAccountId,
    pub refresh_token: Option<String>,
}

pub(crate) fn now() -> Result<Timestamp, String> {
    Timestamp::now()
}

/// The sign-in root: its loopback test endpoint, else `https://auth.openai.com`.
pub fn auth_root() -> Result<Url, String> {
    Ok(
        crate::llm::variable_endpoint(AUTH_URL_VARIABLE)?.map_or_else(
            || Url::parse(AUTH_ROOT).expect("built-in Codex auth URL"),
            crate::llm::TestEndpoint::into_url,
        ),
    )
}

fn endpoint(root: &Url, route: &str) -> Result<Url, String> {
    let mut url = root.clone();
    url.path_segments_mut()
        .map_err(|_| "Invalid Codex sign-in URL.")?
        .pop_if_empty()
        .push("oauth")
        .push(route);
    Ok(url)
}

/// The configured read-only auth file, if any.
pub fn auth_file() -> Option<PathBuf> {
    crate::platform::var(AUTH_FILE_VARIABLE)
        .filter(|value| !value.is_empty())
        .map(crate::platform::env_path)
}

fn client() -> Result<reqwest::Client, String> {
    reqwest::Client::builder()
        .redirect(reqwest::redirect::Policy::none())
        .retry(reqwest::retry::never())
        .timeout(AUTH_HTTP_TIMEOUT)
        .build()
        .map_err(|_| "Cannot initialize the Codex sign-in HTTP client.".into())
}

/// The JSON claims of a JWT, read without verifying its signature, as Pi does: the
/// token came over TLS from the token endpoint or from the user's own auth file.
fn claims(token: &str) -> Option<JwtClaims> {
    let mut parts = token.split('.');
    let (_, payload, _, None) = (parts.next()?, parts.next()?, parts.next()?, parts.next()) else {
        return None;
    };
    let bytes = URL_SAFE_NO_PAD
        .decode(payload)
        .or_else(|_| URL_SAFE.decode(payload))
        .ok()?;
    serde_json::from_slice(&bytes).ok()
}

impl JwtClaims {
    fn account_id(self) -> Option<crate::names::CodexAccountId> {
        self.auth.0?.0.chatgpt_account_id.0
    }
}

#[derive(Default, Deserialize)]
struct JwtClaims {
    #[serde(default)]
    exp: crate::json::Optional<Timestamp>,
    #[serde(default, rename = "https://api.openai.com/auth")]
    auth: crate::json::Optional<crate::json::Object<AccountClaim>>,
}
#[derive(Default, Deserialize)]
struct AccountClaim {
    #[serde(default)]
    chatgpt_account_id: crate::json::Optional<crate::names::CodexAccountId>,
}

#[derive(Deserialize)]
struct TokenResponse {
    access_token: Option<String>,
    refresh_token: Option<String>,
    #[serde(
        default,
        deserialize_with = "timestamp::optional_duration::deserialize"
    )]
    expires_in: Option<Duration>,
}

fn credentials(tokens: TokenResponse, saved_at: Timestamp) -> Result<Credentials, String> {
    let invalid = || "Invalid Codex token response; nothing was saved.".to_owned();
    let access_token = tokens.access_token.filter(|token| !token.is_empty());
    let refresh_token = tokens.refresh_token.filter(|token| !token.is_empty());
    let (Some(access_token), Some(refresh_token), Some(expires_in)) = (
        access_token,
        refresh_token,
        tokens.expires_in.filter(|duration| !duration.is_zero()),
    ) else {
        return Err(invalid());
    };
    let account_id = claims(&access_token)
        .and_then(JwtClaims::account_id)
        .ok_or("The Codex access token names no ChatGPT account; nothing was saved.")?;
    Ok(Credentials {
        access_token,
        refresh_token,
        account_id,
        expires_at: saved_at.checked_add(expires_in).ok_or_else(invalid)?,
        saved_at,
    })
}

#[derive(Default, Deserialize)]
struct OAuthError {
    error: Option<OAuthErrorField>,
    code: Option<OAuthCode>,
}

#[derive(Deserialize)]
#[serde(untagged)]
enum OAuthErrorField {
    Text(String),
    Object { code: Option<OAuthCode> },
    Other(serde::de::IgnoredAny),
}

#[derive(Deserialize)]
#[serde(untagged)]
enum OAuthCode {
    Text(String),
    Other(serde::de::IgnoredAny),
}

impl OAuthCode {
    fn text(&self) -> Option<&str> {
        match self {
            Self::Text(code) => Some(code),
            Self::Other(_) => None,
        }
    }
}

impl OAuthError {
    fn code(&self) -> Option<&str> {
        let error = match &self.error {
            Some(OAuthErrorField::Text(code)) => Some(code.as_str()),
            Some(OAuthErrorField::Object { code }) => code.as_ref().and_then(OAuthCode::text),
            _ => None,
        };
        error.or_else(|| self.code.as_ref().and_then(OAuthCode::text))
    }
}

/// Refresh errors after which the refresh token can never work again.
fn terminal(code: &str) -> bool {
    matches!(
        code,
        "invalid_grant"
            | "refresh_token_expired"
            | "refresh_token_reused"
            | "refresh_token_invalidated"
    )
}

enum Exchange {
    Authorization,
    Refresh,
}

enum ExchangeError {
    TerminalRefresh,
    Unavailable(TokenError),
}

impl From<TokenError> for ExchangeError {
    fn from(error: TokenError) -> Self {
        Self::Unavailable(error)
    }
}

impl ExchangeError {
    fn diagnostic(self) -> TokenError {
        match self {
            Self::TerminalRefresh => {
                "The Codex refresh token is no longer valid; run `artifactize login codex`.".into()
            }
            Self::Unavailable(error) => error,
        }
    }
}

fn rejected(exchange: Exchange, status: reqwest::StatusCode, code: Option<&str>) -> ExchangeError {
    let number = status.as_u16();
    let message = match exchange {
        Exchange::Refresh if code.is_some_and(terminal) => return ExchangeError::TerminalRefresh,
        Exchange::Refresh => {
            format!("Codex token refresh failed (HTTP {number}); the stored sign-in was kept.")
        }
        Exchange::Authorization if code == Some("invalid_grant") => {
            "The Codex authorization code was rejected; run `artifactize login codex` again.".into()
        }
        Exchange::Authorization => format!("Codex sign-in failed (HTTP {number})."),
    };
    ExchangeError::Unavailable(TokenError {
        transient: status == reqwest::StatusCode::TOO_MANY_REQUESTS || status.is_server_error(),
        message,
    })
}

/// POST a form to the token endpoint. Neither error body nor error code is diagnostic text.
async fn token_request(
    root: &Url,
    form: &[(&str, &str)],
    exchange: Exchange,
) -> Result<TokenResponse, ExchangeError> {
    let response = client()
        .map_err(TokenError::from)?
        .post(endpoint(root, "token").map_err(TokenError::from)?)
        .form(form)
        .send()
        .await
        .map_err(|_| TokenError {
            transient: true,
            message:
                "Codex token request failed; check your connection. The stored sign-in was kept."
                    .into(),
        })?;
    let status = response.status();
    if !status.is_success() {
        let body: OAuthError = response.json().await.unwrap_or_default();
        return Err(rejected(exchange, status, body.code()));
    }
    response
        .json()
        .await
        .map_err(|_| TokenError::from("Invalid Codex token response; nothing was saved.").into())
}

/// A usable token: from the read-only auth file when one is set, else artifactize's own,
/// refreshed under a cross-process lock when it is about to expire.
pub(crate) async fn access_token(location: Result<&Location, &str>) -> Result<Token, TokenError> {
    if let Some(path) = auth_file() {
        return Ok(read_auth_file_at(&path, now()?)?.token);
    }
    stored_token(&Storage::new(location?)?, &auth_root()?).await
}

async fn stored_token(storage: &Storage, root: &Url) -> Result<Token, TokenError> {
    stored_token_at(storage, root, now).await
}

async fn stored_token_at(
    storage: &Storage,
    root: &Url,
    clock: impl Fn() -> Result<Timestamp, String>,
) -> Result<Token, TokenError> {
    let _lock = storage.lock(LOCK).await?;
    let stored = read_stored(storage)?.ok_or(LOGIN_REQUIRED)?;
    if stored.expires_at > clock()?.saturating_add(REFRESH_MARGIN) {
        return Ok(Token {
            access_token: stored.access_token,
            refresh_token: Some(stored.refresh_token),
            account_id: stored.account_id,
        });
    }
    stored.publish(storage)?;
    let tokens = token_request(
        root,
        &[
            ("grant_type", "refresh_token"),
            ("refresh_token", &stored.refresh_token),
            ("client_id", CLIENT_ID),
        ],
        Exchange::Refresh,
    )
    .await;
    let tokens = match tokens {
        Ok(tokens) => tokens,
        Err(error) => {
            if matches!(error, ExchangeError::TerminalRefresh) {
                storage.remove(CREDENTIALS)?;
            }
            let mut failure = error.diagnostic();
            failure.message = crate::secret::Inventory::new(stored.values().map(str::to_owned))
                .scrub(&failure.message);
            return Err(failure);
        }
    };
    let refreshed = credentials(tokens, clock()?)?;
    if refreshed.account_id != stored.account_id {
        return Err(
            "The refreshed Codex token is for another ChatGPT account; run `artifactize login codex`."
                .into(),
        );
    }
    refreshed.publish(storage)?;
    storage.save(CREDENTIALS, &refreshed)?;
    Ok(Token {
        access_token: refreshed.access_token,
        refresh_token: Some(refreshed.refresh_token),
        account_id: refreshed.account_id,
    })
}

/// Known read-only import fields. Wrong-typed optional fields retain the old missing/null
/// behavior; extra fields are ignored and no credential data is echoed in parse errors.
/// A read-only file can carry a usable token without an expiry claim. An expired
/// file reports no timestamp because the existing reader refuses it before returning a token.
#[derive(Debug)]
pub enum FileExpiry {
    Usable { expires_at: Option<Timestamp> },
    Expired,
}

/// Owned credentials always carry the expiry saved by the token exchange.
#[derive(Debug)]
pub enum StoredExpiry {
    Usable { expires_at: Timestamp },
    Expired { expires_at: Timestamp },
}

/// Offline sign-in states: only file states have a path, only stored states have
/// a mandatory expiry, and a storage refusal can only accompany an absent sign-in.
pub enum Status {
    Absent,
    Refused { reason: String },
    File { path: PathBuf, expiry: FileExpiry },
    Stored { expiry: StoredExpiry },
}

impl std::fmt::Debug for Status {
    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Absent => formatter.write_str("Absent"),
            Self::Refused { reason } => formatter
                .debug_struct("Refused")
                .field("reason", reason)
                .finish(),
            Self::File { path, expiry } => formatter
                .debug_struct("File")
                .field("path", &crate::platform::path_text(path))
                .field("expiry", expiry)
                .finish(),
            Self::Stored { expiry } => formatter
                .debug_struct("Stored")
                .field("expiry", expiry)
                .finish(),
        }
    }
}

impl Serialize for Status {
    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        use serde::ser::SerializeStruct;
        // Keep the pre-enum JSON contract exactly at the serialization boundary.
        let (source, file, expires_at, expired, refused) = match self {
            Self::Absent => ("none", None, None, false, None),
            Self::Refused { reason } => ("none", None, None, false, Some(reason)),
            Self::File {
                path,
                expiry: FileExpiry::Usable { expires_at },
            } => ("file", Some(path), *expires_at, false, None),
            Self::File {
                path,
                expiry: FileExpiry::Expired,
            } => ("file", Some(path), None, true, None),
            Self::Stored {
                expiry: StoredExpiry::Usable { expires_at },
            } => ("stored", None, Some(*expires_at), false, None),
            Self::Stored {
                expiry: StoredExpiry::Expired { expires_at },
            } => ("stored", None, Some(*expires_at), true, None),
        };
        let mut wire = serializer.serialize_struct(
            "Status",
            3 + usize::from(file.is_some()) + usize::from(refused.is_some()),
        )?;
        wire.serialize_field("source", source)?;
        if let Some(file) = file {
            wire.serialize_field("authFile", &crate::platform::path_text(file))?;
        }
        wire.serialize_field("expiresAt", &expires_at)?;
        wire.serialize_field("expired", &expired)?;
        if let Some(reason) = refused {
            wire.serialize_field("refused", reason)?;
        }
        wire.end()
    }
}

/// Inspect the sign-in offline: no lock, refresh, network or writes.
pub fn status(location: Result<&Location, &str>) -> Result<Status, String> {
    let mut managed = crate::secret::Inventory::read(location.ok(), location.ok());
    let status = read_status(location);
    managed.merge(crate::secret::Inventory::read(location.ok(), location.ok()));
    status
        .map_err(|error| managed.scrub(&error))
        .and_then(|status| public_status(status, &managed))
}

fn public_status(mut status: Status, managed: &crate::secret::Inventory) -> Result<Status, String> {
    let expires_at = match &mut status {
        Status::Absent => None,
        Status::Refused { reason } => {
            *reason = managed.scrub(reason);
            None
        }
        Status::File { path, expiry } => {
            let display = crate::platform::path_text(path);
            if managed.contains(&display) {
                // This is a presentation path, never the path used to read the import.
                *path = PathBuf::new();
            }
            if let FileExpiry::Usable { expires_at } = expiry {
                *expires_at =
                    expires_at.filter(|time| !managed.contains(&time.seconds().to_string()));
            }
            None
        }
        Status::Stored { expiry } => match expiry {
            StoredExpiry::Usable { expires_at } | StoredExpiry::Expired { expires_at } => {
                Some(*expires_at)
            }
        },
    };
    if expires_at.is_some_and(|time| managed.contains(&time.seconds().to_string())) {
        return Err(managed.scrub("Cannot show Codex sign-in expiry safely."));
    }
    Ok(status)
}

fn read_status(location: Result<&Location, &str>) -> Result<Status, String> {
    let now = now()?;
    if let Some(path) = auth_file() {
        // Reading fails on an expiring token; that is a state to report, not an error.
        let expiry = match read_auth_file_at(&path, now) {
            Ok(FileToken { expires_at, .. }) => FileExpiry::Usable { expires_at },
            Err(AuthFileError::Expired(_)) => FileExpiry::Expired,
            Err(error) => return Err(error.into()),
        };
        return Ok(Status::File { path, expiry });
    }
    let location = location?;
    if let Some(reason) = location.refusal(CREDENTIALS)? {
        return Ok(Status::Refused { reason });
    }
    let stored = read_stored(&Storage::inspect(location)?)?;
    Ok(match stored {
        None => Status::Absent,
        Some(stored) => Status::Stored {
            expiry: if stored.expires_at <= now {
                StoredExpiry::Expired {
                    expires_at: stored.expires_at,
                }
            } else {
                StoredExpiry::Usable {
                    expires_at: stored.expires_at,
                }
            },
        },
    })
}

/// Revoke and remove artifactize's own tokens; a read-only auth file is left alone.
/// Returns whether the revocation was confirmed.
pub async fn logout(location: Result<&Location, &str>) -> Result<bool, String> {
    sign_out(
        &Storage::new(location.map_err(str::to_owned)?)?,
        &auth_root()?,
    )
    .await
}

async fn sign_out(storage: &Storage, root: &Url) -> Result<bool, String> {
    let _lock = storage.lock(LOCK).await?;
    let Some(stored) = read_stored(storage)? else {
        return Ok(true);
    };
    stored.publish(storage)?;
    let revoked = revoke(root, &stored.refresh_token).await;
    storage.remove(CREDENTIALS)?;
    Ok(revoked)
}

async fn revoke(root: &Url, refresh_token: &str) -> bool {
    let Ok(client) = client() else {
        return false;
    };
    let Ok(url) = endpoint(root, "revoke") else {
        return false;
    };
    client
        .post(url)
        .timeout(REVOCATION_TIMEOUT)
        .json(
            &json!({"token":refresh_token,"token_type_hint":"refresh_token","client_id":CLIENT_ID}),
        )
        .send()
        .await
        .is_ok_and(|response| response.status().is_success())
}

#[cfg(test)]
mod tests;

/// Inventory stored values without refreshing, revoking or sending anything.
pub(crate) fn secret_values(location: Option<&Location>) -> Result<Vec<String>, String> {
    // Inventory extraction is independent of timestamps, account identifiers and
    // expiry rules needed to use the credentials for sign-in.
    #[derive(Deserialize)]
    struct StoredTokens {
        #[serde(default)]
        access_token: crate::json::Optional<String>,
        #[serde(default)]
        refresh_token: crate::json::Optional<String>,
    }
    let saved = location
        .filter(|location| !location.is_refused())
        .map(|location| Storage::inspect(location)?.read::<StoredTokens>(CREDENTIALS))
        .transpose()?
        .flatten();
    let mut known = saved
        .into_iter()
        .flat_map(|tokens| [tokens.access_token.0, tokens.refresh_token.0])
        .flatten()
        .collect::<Vec<_>>();
    if let Some(path) = auth_file() {
        known.extend(auth_file::secret_values(&path)?);
    }
    Ok(known)
}