From 822c3358642315d3488b7d9e29fda135cf969a8d Mon Sep 17 00:00:00 2001 From: Ruben Rosario Date: Sun, 21 Jun 2026 17:35:31 +0100 Subject: [PATCH] Fix token_has_all_scopes for yup-oauth2 v8 array format yup-oauth2 v8 stores tokens as a JSON array of entries, each with a 'scopes' array field. Updated the parser to iterate over entries and check for matching scopes. --- src/infrastructure/api.rs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/infrastructure/api.rs b/src/infrastructure/api.rs index d8917f6..9be184d 100644 --- a/src/infrastructure/api.rs +++ b/src/infrastructure/api.rs @@ -78,15 +78,24 @@ impl ApiClient { Ok(c) => c, Err(_) => return false, }; - let value: serde_json::Value = match serde_json::from_str(&content) { + let entries: Vec = match serde_json::from_str(&content) { Ok(v) => v, Err(_) => return false, }; - let scope = match value["scope"].as_str() { - Some(s) => s, - None => return false, - }; - SCOPES.iter().all(|s| scope.contains(s)) + for entry in &entries { + let scopes = match entry["scopes"].as_array() { + Some(s) => s, + None => continue, + }; + let has_all: Vec<&str> = scopes + .iter() + .filter_map(|s| s.as_str()) + .collect(); + if SCOPES.iter().all(|s| has_all.contains(s)) { + return true; + } + } + false } pub async fn start_and_wait_for_auth(&self) -> Result<(), ApiError> {