mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-23 00:47:33 +00:00
fix: Actually config-gate MSC4484 support
This commit is contained in:
1 parent
f3cbfed721
commit
cebeee6bae
5 files changed
+27
-12
No files matched your search
@@ -1,7 +1,7 @@
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
use axum::extract::State;
|
||||
use conduwuit::{Result, Server};
|
||||
use conduwuit::{Result, Server, config::experiments::ToggledExperiment};
|
||||
use ruma::{
|
||||
RoomVersionId,
|
||||
api::{
|
||||
@@ -53,8 +53,11 @@ pub(crate) async fn get_capabilities_route(
|
||||
capabilities.account_moderation.lock = true;
|
||||
capabilities.account_moderation.suspend = true;
|
||||
|
||||
capabilities.admin =
|
||||
AdminCapability::new(BTreeSet::from_iter([OAuthClientScope::ServerAdministration]));
|
||||
if services.config.experiments.msc4484.is_enabled() {
|
||||
capabilities.admin = AdminCapability::new(BTreeSet::from_iter([
|
||||
OAuthClientScope::ServerAdministration,
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
capabilities.profile_fields = Some(
|
||||
|
||||
@@ -5,7 +5,9 @@ use std::{
|
||||
};
|
||||
|
||||
use conduwuit::{
|
||||
Err, Error, Result, err,
|
||||
Err, Error, Result,
|
||||
config::experiments::ToggledExperiment,
|
||||
err,
|
||||
utils::{IterStream, millis_since_unix_epoch},
|
||||
};
|
||||
use http::StatusCode;
|
||||
@@ -343,7 +345,9 @@ async fn check_access_token(
|
||||
} else {
|
||||
let mut scopes = BTreeSet::from_iter([OAuthClientScope::ApiFullAccess]);
|
||||
|
||||
if services.admin.user_is_admin(&sender_user).await {
|
||||
if services.config.experiments.msc4484.is_enabled()
|
||||
&& services.admin.user_is_admin(&sender_user).await
|
||||
{
|
||||
scopes.insert(OAuthClientScope::ServerAdministration);
|
||||
}
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ pub struct RawScopes(String);
|
||||
|
||||
impl RawScopes {
|
||||
#[allow(clippy::trivial_regex)]
|
||||
pub fn to_scopes(&self) -> Result<RequestedScopes, String> {
|
||||
pub fn to_scopes(&self, msc4484: bool) -> Result<RequestedScopes, String> {
|
||||
let client_api_token_regex =
|
||||
regex!(r"urn:matrix:(client|org.matrix.msc2967.client):api:\*");
|
||||
let device_token_regex =
|
||||
@@ -121,7 +121,7 @@ impl RawScopes {
|
||||
let scope_was_new = {
|
||||
if client_api_token_regex.is_match(token) {
|
||||
scopes.scopes.insert(OAuthClientScope::ApiFullAccess)
|
||||
} else if server_administration_regex.is_match(token) {
|
||||
} else if msc4484 && server_administration_regex.is_match(token) {
|
||||
scopes.scopes.insert(OAuthClientScope::ServerAdministration)
|
||||
} else if let Some(captures) = device_token_regex.captures(token) {
|
||||
scopes
|
||||
|
||||
@@ -6,7 +6,9 @@ use std::{
|
||||
|
||||
use base64::Engine;
|
||||
use conduwuit::{
|
||||
Result, SyncMutex, info,
|
||||
Result, SyncMutex,
|
||||
config::experiments::ToggledExperiment,
|
||||
info,
|
||||
utils::{self, hash::sha256},
|
||||
};
|
||||
use database::{Deserialized, Json, Map};
|
||||
@@ -284,7 +286,9 @@ impl Service {
|
||||
}
|
||||
}
|
||||
|
||||
let requested_scopes = query.scope.to_scopes()?;
|
||||
let requested_scopes = query
|
||||
.scope
|
||||
.to_scopes(self.services.config.experiments.msc4484.is_enabled())?;
|
||||
|
||||
let redirect_uri_query_separator = match query.response_mode {
|
||||
| ResponseMode::Fragment => '#',
|
||||
@@ -343,7 +347,7 @@ impl Service {
|
||||
|
||||
let requested_scopes = query
|
||||
.scope
|
||||
.to_scopes()
|
||||
.to_scopes(self.services.config.experiments.msc4484.is_enabled())
|
||||
.map_err(|err| OAuthError::new(ErrorCode::InvalidGrant, err))?;
|
||||
|
||||
let device_code = Self::generate_token();
|
||||
@@ -762,6 +766,7 @@ impl Service {
|
||||
scopes: &BTreeSet<OAuthClientScope>,
|
||||
) -> Result<(), OAuthError> {
|
||||
if scopes.contains(&OAuthClientScope::ServerAdministration)
|
||||
&& self.services.config.experiments.msc4484.is_enabled()
|
||||
&& !self.services.admin.user_is_admin(authorizing_user).await
|
||||
{
|
||||
return Err(OAuthError::new(
|
||||
|
||||
@@ -4,6 +4,7 @@ use axum::{
|
||||
response::Redirect,
|
||||
routing::on,
|
||||
};
|
||||
use conduwuit_core::config::experiments::ToggledExperiment;
|
||||
use conduwuit_service::oauth::{
|
||||
SessionInfo,
|
||||
client_metadata::ClientMetadata,
|
||||
@@ -104,8 +105,10 @@ async fn route_authorization_code(
|
||||
return Err(WebError::BadRequest("Invalid client ID".to_owned()));
|
||||
};
|
||||
|
||||
let RequestedScopes { device_id, mut scopes } =
|
||||
query.scope.to_scopes().map_err(WebError::BadRequest)?;
|
||||
let RequestedScopes { device_id, mut scopes } = query
|
||||
.scope
|
||||
.to_scopes(services.config.experiments.msc4484.is_enabled())
|
||||
.map_err(WebError::BadRequest)?;
|
||||
|
||||
let existing_session_info = if let Some(device_id) = &device_id {
|
||||
services
|
||||
|
||||
Reference in new issue
Block a user