Skip to main content

auth_check/
auth_check.rs

1use ai_cortex_sdk::{CortexClient, CortexConfig};
2
3/// 验证 PAT 是否有效:用 PAT 列一次软件目录,成功即凭证可用。
4///
5/// Usage:
6///   cargo run --example auth_check -- <PAT>
7#[tokio::main]
8async fn main() {
9    let pat = std::env::args()
10        .nth(1)
11        .unwrap_or_else(|| "REPLACE_WITH_YOUR_PAT".to_string());
12
13    // software_id 占位:心跳会按此软件的许可证校验设备上限。
14    let software_id = "00000000-0000-0000-0000-000000000000".to_string();
15
16    let config = CortexConfig::new("http://localhost:40404", pat, software_id);
17    let client = CortexClient::new(config);
18
19    match client.list_software().await {
20        Ok(items) => {
21            println!("PAT valid. Software store returned {} item(s).", items.len());
22        }
23        Err(e) => {
24            eprintln!("PAT check failed: {e}");
25            std::process::exit(1);
26        }
27    }
28
29    println!("\n--- My Devices ---");
30    match client.list_devices().await {
31        Ok(devices) => {
32            println!("{} bound device(s).", devices.len());
33            for d in devices {
34                println!(
35                    "- fingerprint={}, last_active={}",
36                    d.fingerprint, d.last_active_time
37                );
38            }
39        }
40        Err(e) => eprintln!("List devices failed: {e}"),
41    }
42}