fix: Don't bail on unrecognized OAuth scopes

This commit is contained in:
Ginger committed 2026-10-01 14:44:08 -04:00
1 parent bf42c6a6cb
commit c18b01dc2d
1 file changed
+5 -7
+5 -7
View File
@@ -115,7 +115,8 @@ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
| Self::ClientApi => write!(f, "urn:matrix:client:api:*"),
| Self::Device(device_id) => write!(f, "urn:matrix:client:device:{device_id}"),
| Self::ServerAdministration => write!(f, "urn:matrix:client:cc.c10y.msc4484.server_administration"),
| Self::ServerAdministration =>
write!(f, "urn:matrix:client:cc.c10y.msc4484.server_administration"),
}
}
}
@@ -130,7 +131,8 @@ pub fn to_scopes(&self) -> Result<HashSet<RequestedScope>, String> {
regex!(r"urn:matrix:(client|org.matrix.msc2967.client):api:\*");
let device_token_regex =
regex!(r"urn:matrix:(client|org.matrix.msc2967.client):device:([a-zA-Z0-9-._~]{5,})");
let server_administration_regex = regex!(r"urn:matrix:client:cc.c10y.msc4484.server_administration");
let server_administration_regex =
regex!(r"urn:matrix:client:cc.c10y.msc4484.server_administration");
let mut scopes = HashSet::new();
@@ -143,12 +145,8 @@ pub fn to_scopes(&self) -> Result<HashSet<RequestedScope>, String> {
} else if let Some(captures) = device_token_regex.captures(token) {
scopes
.insert(RequestedScope::Device(captures.get(2).unwrap().as_str().into()))
} else if token == "openid" {
// TODO(unspecced): Element sets this scope but doesn't use
// it for anything
true
} else {
return Err(format!("Invalid scope: {token}"));
continue;
}
};