mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-29 03: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
@@ -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(
|
||||
|
||||
Reference in new issue
Block a user