From 4a4c25843b8d832fa3be0f3af59b245263fed9c9 Mon Sep 17 00:00:00 2001 From: Ginger Date: Mon, 23 Nov 2026 09:26:50 -0500 Subject: [PATCH] fix: Return the correct scope list when refreshing an OAuth access token --- src/service/oauth/mod.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/service/oauth/mod.rs b/src/service/oauth/mod.rs index a234552ed..81a48426a 100644 --- a/src/service/oauth/mod.rs +++ b/src/service/oauth/mod.rs @@ -1,5 +1,6 @@ use std::{ collections::{BTreeSet, HashMap}, + fmt::Write, sync::Arc, time::{Duration, SystemTime}, }; @@ -73,6 +74,15 @@ impl SessionInfo { pub fn scopes(&self) -> BTreeSet { self.scopes.union(&self.temporary_scopes).cloned().collect() } + + #[must_use] + pub fn scope_string(&self, device_id: &DeviceId) -> String { + let mut scopes = self.scopes().iter().join(" "); + + let _ = write!(scopes, " urn:matrix:client:device:{device_id}"); + + scopes + } } #[derive(Debug, Deserialize, Serialize)] @@ -767,9 +777,7 @@ impl Service { panic!("refresh token is not current or previous for its session"); } - // TODO: this doesn't include the device ID "scope", do any clients rely - // on that? - let scope = session_info.scopes.iter().join(" "); + let scope = session_info.scope_string(&refresh_token_info.device_id); let new_access_token = DeviceToken::new_random().with_max_age(Self::ACCESS_TOKEN_MAX_AGE);