feat(sdk): Use stable OAuth 2.0 login scopes
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
This commit is contained in:
committed by
Damir Jelić
parent
d6c666a88d
commit
14b21e2a9a
@@ -8,6 +8,8 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
### Features
|
||||
|
||||
- The scopes sent when logging in with the `OAuth` API now use the stable prefix defined in the
|
||||
specification.
|
||||
- [**breaking**]: The unread count computation has now moved from the sliding sync processing, to
|
||||
the event cache. As a result, it is necessary to enable the event cache if you want to keep a
|
||||
precise unread counts, using `Client::event_cache().subscribe()`. The unread counts will now also
|
||||
|
||||
@@ -759,10 +759,9 @@ impl OAuth {
|
||||
additional_scopes: Option<Vec<Scope>>,
|
||||
) -> (Vec<Scope>, OwnedDeviceId) {
|
||||
/// Scope to grand full access to the client-server API.
|
||||
const SCOPE_MATRIX_CLIENT_SERVER_API_FULL_ACCESS: &str =
|
||||
"urn:matrix:org.matrix.msc2967.client:api:*";
|
||||
const SCOPE_MATRIX_CLIENT_SERVER_API_FULL_ACCESS: &str = "urn:matrix:client:api:*";
|
||||
/// Prefix of the scope to bind a device ID to an access token.
|
||||
const SCOPE_MATRIX_DEVICE_ID_PREFIX: &str = "urn:matrix:org.matrix.msc2967.client:device:";
|
||||
const SCOPE_MATRIX_DEVICE_ID_PREFIX: &str = "urn:matrix:client:device:";
|
||||
|
||||
// Generate the device ID if it is not provided.
|
||||
let device_id = device_id.unwrap_or_else(DeviceId::new);
|
||||
|
||||
@@ -92,25 +92,21 @@ async fn check_authorization_url(
|
||||
assert!(actual_scopes.len() >= 2, "Expected at least two scopes");
|
||||
|
||||
assert!(
|
||||
actual_scopes
|
||||
.contains(&"urn:matrix:org.matrix.msc2967.client:api:*".to_owned()),
|
||||
actual_scopes.contains(&"urn:matrix:client:api:*".to_owned()),
|
||||
"Expected Matrix API scope not found in scopes"
|
||||
);
|
||||
|
||||
// Only check the device ID if we know it. If it's generated randomly we don't
|
||||
// know it.
|
||||
if let Some(device_id) = device_id {
|
||||
let device_id_scope =
|
||||
format!("urn:matrix:org.matrix.msc2967.client:device:{device_id}");
|
||||
let device_id_scope = format!("urn:matrix:client:device:{device_id}");
|
||||
assert!(
|
||||
actual_scopes.contains(&device_id_scope),
|
||||
"Expected device ID scope not found in scopes"
|
||||
)
|
||||
} else {
|
||||
assert!(
|
||||
actual_scopes
|
||||
.iter()
|
||||
.any(|s| s.starts_with("urn:matrix:org.matrix.msc2967.client:device:")),
|
||||
actual_scopes.iter().any(|s| s.starts_with("urn:matrix:client:device:")),
|
||||
"Expected device ID scope not found in scopes"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user