mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-27 02:47:33 +00:00
fix: Work around MSC4484 lockout when disabled
This commit is contained in:
1 parent
62fc507798
commit
49207a42f8
4 files changed
+16
-21
No files matched your search
+10
-10
@@ -340,19 +340,19 @@ async fn check_access_token(
|
|||||||
.map(Box::new);
|
.map(Box::new);
|
||||||
|
|
||||||
// Make sure the user has the right scopes to use the route
|
// Make sure the user has the right scopes to use the route
|
||||||
let user_scopes = if let Some(session_info) = &session_info {
|
let mut user_scopes = if let Some(session_info) = &session_info {
|
||||||
session_info.scopes()
|
session_info.scopes()
|
||||||
} else {
|
} else {
|
||||||
let mut scopes = BTreeSet::from_iter([OAuthClientScope::ApiFullAccess]);
|
BTreeSet::from_iter([OAuthClientScope::ApiFullAccess])
|
||||||
|
|
||||||
if services.config.experiments.msc4484.is_enabled()
|
|
||||||
&& services.admin.user_is_admin(&sender_user).await
|
|
||||||
{
|
|
||||||
scopes.insert(OAuthClientScope::ServerAdministration);
|
|
||||||
}
|
|
||||||
|
|
||||||
scopes
|
|
||||||
};
|
};
|
||||||
|
if (!services.config.experiments.msc4484.is_enabled() || session_info.is_none())
|
||||||
|
&& services.admin.user_is_admin(&sender_user).await
|
||||||
|
{
|
||||||
|
// This is required to make sure admin APIs still work when msc4484
|
||||||
|
// is disabled.
|
||||||
|
// https://forgejo.ellis.link/continuwuation/continuwuity/pulls/2533#issuecomment-40042
|
||||||
|
user_scopes.insert(OAuthClientScope::ServerAdministration);
|
||||||
|
}
|
||||||
|
|
||||||
if !required_scopes
|
if !required_scopes
|
||||||
.iter()
|
.iter()
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ pub struct RawScopes(String);
|
|||||||
|
|
||||||
impl RawScopes {
|
impl RawScopes {
|
||||||
#[allow(clippy::trivial_regex)]
|
#[allow(clippy::trivial_regex)]
|
||||||
pub fn to_scopes(&self, msc4484: bool) -> Result<RequestedScopes, String> {
|
pub fn to_scopes(&self) -> Result<RequestedScopes, String> {
|
||||||
let client_api_token_regex =
|
let client_api_token_regex =
|
||||||
regex!(r"urn:matrix:(client|org.matrix.msc2967.client):api:\*");
|
regex!(r"urn:matrix:(client|org.matrix.msc2967.client):api:\*");
|
||||||
let device_token_regex =
|
let device_token_regex =
|
||||||
@@ -121,7 +121,7 @@ impl RawScopes {
|
|||||||
let scope_was_new = {
|
let scope_was_new = {
|
||||||
if client_api_token_regex.is_match(token) {
|
if client_api_token_regex.is_match(token) {
|
||||||
scopes.scopes.insert(OAuthClientScope::ApiFullAccess)
|
scopes.scopes.insert(OAuthClientScope::ApiFullAccess)
|
||||||
} else if msc4484 && server_administration_regex.is_match(token) {
|
} else if server_administration_regex.is_match(token) {
|
||||||
scopes.scopes.insert(OAuthClientScope::ServerAdministration)
|
scopes.scopes.insert(OAuthClientScope::ServerAdministration)
|
||||||
} else if let Some(captures) = device_token_regex.captures(token) {
|
} else if let Some(captures) = device_token_regex.captures(token) {
|
||||||
scopes
|
scopes
|
||||||
|
|||||||
@@ -286,9 +286,7 @@ impl Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let requested_scopes = query
|
let requested_scopes = query.scope.to_scopes()?;
|
||||||
.scope
|
|
||||||
.to_scopes(self.services.config.experiments.msc4484.is_enabled())?;
|
|
||||||
|
|
||||||
let redirect_uri_query_separator = match query.response_mode {
|
let redirect_uri_query_separator = match query.response_mode {
|
||||||
| ResponseMode::Fragment => '#',
|
| ResponseMode::Fragment => '#',
|
||||||
@@ -347,7 +345,7 @@ impl Service {
|
|||||||
|
|
||||||
let requested_scopes = query
|
let requested_scopes = query
|
||||||
.scope
|
.scope
|
||||||
.to_scopes(self.services.config.experiments.msc4484.is_enabled())
|
.to_scopes()
|
||||||
.map_err(|err| OAuthError::new(ErrorCode::InvalidGrant, err))?;
|
.map_err(|err| OAuthError::new(ErrorCode::InvalidGrant, err))?;
|
||||||
|
|
||||||
let device_code = Self::generate_token();
|
let device_code = Self::generate_token();
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ use axum::{
|
|||||||
response::Redirect,
|
response::Redirect,
|
||||||
routing::on,
|
routing::on,
|
||||||
};
|
};
|
||||||
use conduwuit_core::config::experiments::ToggledExperiment;
|
|
||||||
use conduwuit_service::oauth::{
|
use conduwuit_service::oauth::{
|
||||||
SessionInfo,
|
SessionInfo,
|
||||||
client_metadata::ClientMetadata,
|
client_metadata::ClientMetadata,
|
||||||
@@ -105,10 +104,8 @@ async fn route_authorization_code(
|
|||||||
return Err(WebError::BadRequest("Invalid client ID".to_owned()));
|
return Err(WebError::BadRequest("Invalid client ID".to_owned()));
|
||||||
};
|
};
|
||||||
|
|
||||||
let RequestedScopes { device_id, mut scopes } = query
|
let RequestedScopes { device_id, mut scopes } =
|
||||||
.scope
|
query.scope.to_scopes().map_err(WebError::BadRequest)?;
|
||||||
.to_scopes(services.config.experiments.msc4484.is_enabled())
|
|
||||||
.map_err(WebError::BadRequest)?;
|
|
||||||
|
|
||||||
let existing_session_info = if let Some(device_id) = &device_id {
|
let existing_session_info = if let Some(device_id) = &device_id {
|
||||||
services
|
services
|
||||||
|
|||||||
Reference in new issue
Block a user