Skip to content

Commit 933373a

Browse files
committed
feat: enhance API token management and UI improvements
- Added `nickname`, `data_scopes`, and `operation_scopes` fields to `ApiTokenMetadata` and `IssuedApiToken` structs. - Updated API token issuance to handle new scopes in the `issueApiToken` function. - Enhanced the Settings UI to include checkboxes for selecting data and operation scopes when issuing tokens. - Improved localization for new scopes in English, Simplified Chinese, and Traditional Chinese. - Refactored CSS for better styling of settings cards and UI elements. - Introduced a new skin texture "aurora" and updated the default texture to use it. - Adjusted background styles and colors for improved visual consistency across the application.
1 parent b13f70e commit 933373a

19 files changed

Lines changed: 367 additions & 162 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
1818
- **Official experience widgets** — added Skin Preview, Layout Switcher, Widget Health, and Focus Streak widgets.
1919
- **Widget diagnostics** — added redacted skin snapshot export, contrast checking, reduced-motion support, compact widget mode, and Widget Dev Harness diagnostics with capability simulation, hash inspection, logs, and auto-reload.
2020
- **Update flow tests** — added coverage for update checking, download confirmation, download progress, install confirmation, and unavailable updater states.
21+
- **Scoped Local API credentials** — API credentials now have a nickname and independently configured data-access and operation permissions, with revocation and one-time secret reveal/copy behavior.
22+
- **Local API permission picker** — Settings now provides localized multi-select controls for the Local API's supported read, subscription, and write scopes.
2123

2224
### Changed
2325

@@ -31,6 +33,9 @@ Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
3133
- **Third-party widget recovery** — failed widgets now show recovery guidance and a real remount/retry action.
3234
- **Update confirmation policy** — automatic and manual update checks now use the same explicit flow: confirm download first, then confirm installation after download completes.
3335
- **Cross-window events** — todo, focus, active-window, goal, interruption, skin, and widget-refresh events now update relevant windows without requiring a full app restart.
36+
- **Extension Bridge compatibility** — legacy extension bridge keys remain fully authorized for existing integrations but are no longer exposed in Settings.
37+
- **Settings presentation** — neutral texture options include an aurora gradient, and Settings surfaces use lighter, transparent grouping backgrounds so the active skin remains visible.
38+
- **Themed switches** — Settings toggles use the active palette's accent color, including the default blue palette, instead of native white controls.
3439

3540
### Fixed
3641

‎src-tauri/src/commands/data_reliability_cmd.rs‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -564,14 +564,17 @@ fn build_bundle(conn: &rusqlite::Connection) -> Result<BackupBundle, String> {
564564
let scopes_json: String = row.get(3)?;
565565
Ok(ApiTokenMetadata {
566566
id: row.get(0)?,
567-
label: row.get(1)?,
568-
token_hash: row.get(2)?,
567+
nickname: row.get(1)?,
568+
label: row.get(2)?,
569+
token_hash: row.get(3)?,
570+
data_scopes: parse_scopes_json(&row.get::<_, String>(4)?),
571+
operation_scopes: parse_scopes_json(&row.get::<_, String>(5)?),
569572
scopes: parse_scopes_json(&scopes_json),
570-
created_at: row.get(4)?,
571-
expires_at: row.get(5)?,
572-
revoked_at: row.get(6)?,
573-
last_used_at: row.get(7)?,
574-
last_client_id: row.get(8)?,
573+
created_at: row.get(7)?,
574+
expires_at: row.get(8)?,
575+
revoked_at: row.get(9)?,
576+
last_used_at: row.get(10)?,
577+
last_client_id: row.get(11)?,
575578
})
576579
})
577580
.map_err(|e| e.to_string())?;

‎src-tauri/src/commands/extension_bridge_cmd.rs‎

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,32 @@ pub(crate) fn hash_token(token: &str) -> String {
5555
pub(crate) fn issue_api_token_impl(
5656
db: &Connection,
5757
label: String,
58-
scopes: Vec<String>,
58+
data_scopes: Vec<String>,
59+
operation_scopes: Vec<String>,
5960
expires_at: Option<String>,
6061
) -> Result<IssuedApiToken, String> {
6162
let trimmed_label = label.trim();
6263
if trimmed_label.is_empty() {
6364
return Err("label cannot be empty".to_string());
6465
}
6566

67+
let nickname = trimmed_label.to_string();
68+
let normalized_data: Vec<String> = data_scopes
69+
.into_iter()
70+
.map(|s| s.trim().to_string())
71+
.filter(|s| !s.is_empty())
72+
.collect();
73+
let normalized_operations: Vec<String> = operation_scopes
74+
.into_iter()
75+
.map(|s| s.trim().to_string())
76+
.filter(|s| !s.is_empty())
77+
.collect();
78+
let scopes = {
79+
let mut merged = normalized_data.clone();
80+
merged.extend(normalized_operations.iter().cloned());
81+
merged
82+
};
83+
6684
let token_id = Uuid::new_v4().to_string();
6785
let secret = format!("{}.{}", Uuid::new_v4(), Uuid::new_v4());
6886
let token_hash = hash_token(&secret);
@@ -76,8 +94,11 @@ pub(crate) fn issue_api_token_impl(
7694
db::insert_api_token(
7795
db,
7896
&token_id,
97+
&nickname,
7998
trimmed_label,
8099
&token_hash,
100+
&normalized_data,
101+
&normalized_operations,
81102
&normalized_scopes,
82103
&now,
83104
expires_at.as_deref(),
@@ -87,8 +108,11 @@ pub(crate) fn issue_api_token_impl(
87108
Ok(IssuedApiToken {
88109
id: token_id,
89110
token: secret,
111+
nickname: nickname.clone(),
90112
label: trimmed_label.to_string(),
91113
scopes: normalized_scopes,
114+
data_scopes: normalized_data,
115+
operation_scopes: normalized_operations,
92116
created_at: now,
93117
expires_at,
94118
})
@@ -97,14 +121,15 @@ pub(crate) fn issue_api_token_impl(
97121
#[tauri::command]
98122
pub fn issue_api_token(
99123
label: String,
100-
scopes: Vec<String>,
124+
data_scopes: Vec<String>,
125+
operation_scopes: Vec<String>,
101126
expires_at: Option<String>,
102127
db_state: tauri::State<super::storage_cmd::DbState>,
103128
) -> Result<IssuedApiToken, String> {
104129
let db = db_state
105130
.lock()
106131
.map_err(|e| format!("Database lock error: {}", e))?;
107-
issue_api_token_impl(&db, label, scopes, expires_at)
132+
issue_api_token_impl(&db, label, data_scopes, operation_scopes, expires_at)
108133
}
109134

110135
#[tauri::command]
@@ -127,7 +152,8 @@ pub fn rotate_api_token(
127152
issue_api_token_impl(
128153
&db,
129154
existing.label,
130-
existing.scopes,
155+
existing.data_scopes,
156+
existing.operation_scopes,
131157
expires_at.or(existing.expires_at),
132158
)
133159
}
@@ -322,4 +348,29 @@ mod tests {
322348
assert!(!verify_request_signature(b"wrong body", &signature, key));
323349
assert!(!verify_request_signature(body, "wrong signature", key));
324350
}
351+
352+
#[test]
353+
fn test_issue_api_token_tracks_nickname_and_grants() {
354+
let conn = rusqlite::Connection::open_in_memory().unwrap();
355+
crate::db::initialize(&conn).unwrap();
356+
357+
let issued = issue_api_token_impl(
358+
&conn,
359+
"vscode-local-client".to_string(),
360+
vec!["usage:read".to_string()],
361+
vec!["session:write".to_string()],
362+
Some("2099-01-01T00:00:00+00:00".to_string()),
363+
)
364+
.unwrap();
365+
366+
assert_eq!(issued.nickname, "vscode-local-client");
367+
assert_eq!(issued.data_scopes, vec!["usage:read"]);
368+
assert_eq!(issued.operation_scopes, vec!["session:write"]);
369+
370+
let listed = crate::db::list_api_tokens(&conn).unwrap();
371+
assert_eq!(listed.len(), 1);
372+
assert_eq!(listed[0].nickname, "vscode-local-client");
373+
assert_eq!(listed[0].data_scopes, vec!["usage:read"]);
374+
assert_eq!(listed[0].operation_scopes, vec!["session:write"]);
375+
}
325376
}

‎src-tauri/src/commands/widget_permissions.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ pub fn issue_widget_api_token(
129129
&conn,
130130
label,
131131
scopes.clone(),
132+
vec![],
132133
None,
133134
)?;
134135

‎src-tauri/src/db/migrations.rs‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,36 @@ fn migration_013_llm_conversations(conn: &Connection) -> Result<()> {
11801180
Ok(())
11811181
}
11821182

1183+
fn migration_014_api_token_permissions(conn: &Connection) -> Result<()> {
1184+
conn.execute(
1185+
"ALTER TABLE api_tokens ADD COLUMN nickname TEXT NOT NULL DEFAULT ''",
1186+
[],
1187+
)?;
1188+
conn.execute(
1189+
"ALTER TABLE api_tokens ADD COLUMN data_scopes_json TEXT NOT NULL DEFAULT '[]'",
1190+
[],
1191+
)?;
1192+
conn.execute(
1193+
"ALTER TABLE api_tokens ADD COLUMN operation_scopes_json TEXT NOT NULL DEFAULT '[]'",
1194+
[],
1195+
)?;
1196+
1197+
conn.execute(
1198+
"UPDATE api_tokens SET nickname = label WHERE nickname = '' OR nickname IS NULL",
1199+
[],
1200+
)?;
1201+
conn.execute(
1202+
"UPDATE api_tokens SET data_scopes_json = scopes_json WHERE data_scopes_json = '[]' OR data_scopes_json IS NULL",
1203+
[],
1204+
)?;
1205+
conn.execute(
1206+
"UPDATE api_tokens SET operation_scopes_json = '[]' WHERE operation_scopes_json IS NULL",
1207+
[],
1208+
)?;
1209+
1210+
Ok(())
1211+
}
1212+
11831213
/// The ordered list of all migrations.
11841214
const MIGRATIONS: &[Migration] = &[
11851215
Migration::new(1, "baseline_schema", migration_001_baseline),
@@ -1215,6 +1245,11 @@ const MIGRATIONS: &[Migration] = &[
12151245
"llm_conversations",
12161246
migration_013_llm_conversations,
12171247
),
1248+
Migration::new(
1249+
14,
1250+
"api_token_permissions",
1251+
migration_014_api_token_permissions,
1252+
),
12181253
];
12191254

12201255
/// Returns the highest migration version defined.

‎src-tauri/src/db/mod.rs‎

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,18 +1226,23 @@ fn parse_scopes_json(raw: String) -> Vec<String> {
12261226
pub fn insert_api_token(
12271227
conn: &Connection,
12281228
id: &str,
1229+
nickname: &str,
12291230
label: &str,
12301231
token_hash: &str,
1232+
data_scopes: &[String],
1233+
operation_scopes: &[String],
12311234
scopes: &[String],
12321235
created_at: &str,
12331236
expires_at: Option<&str>,
12341237
) -> Result<()> {
1238+
let data_scopes_json = serde_json::to_string(data_scopes).unwrap_or_else(|_| "[]".to_string());
1239+
let operation_scopes_json = serde_json::to_string(operation_scopes).unwrap_or_else(|_| "[]".to_string());
12351240
let scopes_json = serde_json::to_string(scopes).unwrap_or_else(|_| "[]".to_string());
12361241
conn.execute(
12371242
"INSERT INTO api_tokens
1238-
(id, label, token_hash, scopes_json, created_at, expires_at)
1239-
VALUES (?1, ?2, ?3, ?4, ?5, ?6)",
1240-
params![id, label, token_hash, scopes_json, created_at, expires_at],
1243+
(id, nickname, label, token_hash, data_scopes_json, operation_scopes_json, scopes_json, created_at, expires_at)
1244+
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9)",
1245+
params![id, nickname, label, token_hash, data_scopes_json, operation_scopes_json, scopes_json, created_at, expires_at],
12411246
)?;
12421247
Ok(())
12431248
}
@@ -1247,46 +1252,52 @@ pub fn get_api_token_by_id(
12471252
id: &str,
12481253
) -> Result<Option<crate::models::ApiTokenMetadata>> {
12491254
let mut stmt = conn.prepare(
1250-
"SELECT id, label, token_hash, scopes_json, created_at, expires_at, revoked_at, last_used_at, last_client_id
1255+
"SELECT id, nickname, label, token_hash, data_scopes_json, operation_scopes_json, scopes_json, created_at, expires_at, revoked_at, last_used_at, last_client_id
12511256
FROM api_tokens
12521257
WHERE id = ?1",
12531258
)?;
12541259
let mut rows = stmt.query(params![id])?;
12551260
if let Some(row) = rows.next()? {
1256-
let scopes_json: String = row.get(3)?;
1261+
let scopes_json: String = row.get(6)?;
12571262
return Ok(Some(crate::models::ApiTokenMetadata {
12581263
id: row.get(0)?,
1259-
label: row.get(1)?,
1260-
token_hash: row.get(2)?,
1264+
nickname: row.get(1)?,
1265+
label: row.get(2)?,
1266+
token_hash: row.get(3)?,
1267+
data_scopes: parse_scopes_json(row.get(4)?),
1268+
operation_scopes: parse_scopes_json(row.get(5)?),
12611269
scopes: parse_scopes_json(scopes_json),
1262-
created_at: row.get(4)?,
1263-
expires_at: row.get(5)?,
1264-
revoked_at: row.get(6)?,
1265-
last_used_at: row.get(7)?,
1266-
last_client_id: row.get(8)?,
1270+
created_at: row.get(7)?,
1271+
expires_at: row.get(8)?,
1272+
revoked_at: row.get(9)?,
1273+
last_used_at: row.get(10)?,
1274+
last_client_id: row.get(11)?,
12671275
}));
12681276
}
12691277
Ok(None)
12701278
}
12711279

12721280
pub fn list_api_tokens(conn: &Connection) -> Result<Vec<crate::models::ApiTokenMetadata>> {
12731281
let mut stmt = conn.prepare(
1274-
"SELECT id, label, token_hash, scopes_json, created_at, expires_at, revoked_at, last_used_at, last_client_id
1282+
"SELECT id, nickname, label, token_hash, data_scopes_json, operation_scopes_json, scopes_json, created_at, expires_at, revoked_at, last_used_at, last_client_id
12751283
FROM api_tokens
12761284
ORDER BY created_at DESC",
12771285
)?;
12781286
let rows = stmt.query_map([], |row| {
1279-
let scopes_json: String = row.get(3)?;
1287+
let scopes_json: String = row.get(6)?;
12801288
Ok(crate::models::ApiTokenMetadata {
12811289
id: row.get(0)?,
1282-
label: row.get(1)?,
1283-
token_hash: row.get(2)?,
1290+
nickname: row.get(1)?,
1291+
label: row.get(2)?,
1292+
token_hash: row.get(3)?,
1293+
data_scopes: parse_scopes_json(row.get(4)?),
1294+
operation_scopes: parse_scopes_json(row.get(5)?),
12841295
scopes: parse_scopes_json(scopes_json),
1285-
created_at: row.get(4)?,
1286-
expires_at: row.get(5)?,
1287-
revoked_at: row.get(6)?,
1288-
last_used_at: row.get(7)?,
1289-
last_client_id: row.get(8)?,
1296+
created_at: row.get(7)?,
1297+
expires_at: row.get(8)?,
1298+
revoked_at: row.get(9)?,
1299+
last_used_at: row.get(10)?,
1300+
last_client_id: row.get(11)?,
12901301
})
12911302
})?;
12921303
rows.collect()
@@ -1328,7 +1339,7 @@ pub fn find_active_api_token_by_hash(
13281339
now: &str,
13291340
) -> Result<Option<crate::models::ApiTokenMetadata>> {
13301341
let mut stmt = conn.prepare(
1331-
"SELECT id, label, token_hash, scopes_json, created_at, expires_at, revoked_at, last_used_at, last_client_id
1342+
"SELECT id, nickname, label, token_hash, data_scopes_json, operation_scopes_json, scopes_json, created_at, expires_at, revoked_at, last_used_at, last_client_id
13321343
FROM api_tokens
13331344
WHERE token_hash = ?1
13341345
AND revoked_at IS NULL
@@ -1337,17 +1348,20 @@ pub fn find_active_api_token_by_hash(
13371348
)?;
13381349
let mut rows = stmt.query(params![token_hash, now])?;
13391350
if let Some(row) = rows.next()? {
1340-
let scopes_json: String = row.get(3)?;
1351+
let scopes_json: String = row.get(6)?;
13411352
return Ok(Some(crate::models::ApiTokenMetadata {
13421353
id: row.get(0)?,
1343-
label: row.get(1)?,
1344-
token_hash: row.get(2)?,
1354+
nickname: row.get(1)?,
1355+
label: row.get(2)?,
1356+
token_hash: row.get(3)?,
1357+
data_scopes: parse_scopes_json(row.get(4)?),
1358+
operation_scopes: parse_scopes_json(row.get(5)?),
13451359
scopes: parse_scopes_json(scopes_json),
1346-
created_at: row.get(4)?,
1347-
expires_at: row.get(5)?,
1348-
revoked_at: row.get(6)?,
1349-
last_used_at: row.get(7)?,
1350-
last_client_id: row.get(8)?,
1360+
created_at: row.get(7)?,
1361+
expires_at: row.get(8)?,
1362+
revoked_at: row.get(9)?,
1363+
last_used_at: row.get(10)?,
1364+
last_client_id: row.get(11)?,
13511365
}));
13521366
}
13531367
Ok(None)

‎src-tauri/src/models/mod.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,11 @@ pub struct ActiveWindowInfo {
330330
#[derive(Debug, Serialize, Deserialize, Clone)]
331331
pub struct ApiTokenMetadata {
332332
pub id: String,
333+
pub nickname: String,
333334
pub label: String,
334335
pub scopes: Vec<String>,
336+
pub data_scopes: Vec<String>,
337+
pub operation_scopes: Vec<String>,
335338
pub created_at: String,
336339
pub expires_at: Option<String>,
337340
pub revoked_at: Option<String>,
@@ -345,8 +348,11 @@ pub struct ApiTokenMetadata {
345348
pub struct IssuedApiToken {
346349
pub id: String,
347350
pub token: String,
351+
pub nickname: String,
348352
pub label: String,
349353
pub scopes: Vec<String>,
354+
pub data_scopes: Vec<String>,
355+
pub operation_scopes: Vec<String>,
350356
pub created_at: String,
351357
pub expires_at: Option<String>,
352358
}

‎src-tauri/src/widget_gateway/mod.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ impl WidgetGateway {
475475
&conn,
476476
format!("Widget: {}", request.widget_id),
477477
granted_scopes,
478+
vec![],
478479
None,
479480
)?;
480481
drop(conn);

0 commit comments

Comments
 (0)