add support for reading a registration token from a file
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
ee1580e480
commit
7a59add8f1
10 changed files with 78 additions and 21 deletions
|
@ -41,6 +41,7 @@ pub struct Service {
|
|||
pub server_user: OwnedUserId,
|
||||
pub admin_alias: OwnedRoomAliasId,
|
||||
pub turn_secret: String,
|
||||
pub registration_token: Option<String>,
|
||||
}
|
||||
|
||||
type RateLimitState = (Instant, u32); // Time if last failed try, number of failed tries
|
||||
|
@ -96,6 +97,20 @@ impl crate::Service for Service {
|
|||
})
|
||||
});
|
||||
|
||||
let registration_token =
|
||||
config
|
||||
.registration_token_file
|
||||
.as_ref()
|
||||
.map_or(config.registration_token.clone(), |path| {
|
||||
let Ok(token) = std::fs::read_to_string(path).inspect_err(|e| {
|
||||
error!("Failed to read the registration token file: {e}");
|
||||
}) else {
|
||||
return config.registration_token.clone();
|
||||
};
|
||||
|
||||
Some(token)
|
||||
});
|
||||
|
||||
let mut s = Self {
|
||||
db,
|
||||
config: config.clone(),
|
||||
|
@ -112,6 +127,7 @@ impl crate::Service for Service {
|
|||
server_user: UserId::parse_with_server_name(String::from("conduit"), &config.server_name)
|
||||
.expect("@conduit:server_name is valid"),
|
||||
turn_secret,
|
||||
registration_token,
|
||||
};
|
||||
|
||||
if !s
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::{
|
|||
use conduit::{
|
||||
err, error, implement, utils,
|
||||
utils::{hash, string::EMPTY},
|
||||
Error, Result, Server,
|
||||
Error, Result,
|
||||
};
|
||||
use database::{Deserialized, Map};
|
||||
use ruma::{
|
||||
|
@ -26,7 +26,6 @@ pub struct Service {
|
|||
}
|
||||
|
||||
struct Services {
|
||||
server: Arc<Server>,
|
||||
globals: Dep<globals::Service>,
|
||||
users: Dep<users::Service>,
|
||||
}
|
||||
|
@ -48,7 +47,6 @@ impl crate::Service for Service {
|
|||
userdevicesessionid_uiaainfo: args.db["userdevicesessionid_uiaainfo"].clone(),
|
||||
},
|
||||
services: Services {
|
||||
server: args.server.clone(),
|
||||
globals: args.depend::<globals::Service>("globals"),
|
||||
users: args.depend::<users::Service>("users"),
|
||||
},
|
||||
|
@ -135,7 +133,13 @@ pub async fn try_auth(
|
|||
uiaainfo.completed.push(AuthType::Password);
|
||||
},
|
||||
AuthData::RegistrationToken(t) => {
|
||||
if Some(t.token.trim()) == self.services.server.config.registration_token.as_deref() {
|
||||
if self
|
||||
.services
|
||||
.globals
|
||||
.registration_token
|
||||
.as_ref()
|
||||
.is_some_and(|reg_token| t.token.trim() == reg_token)
|
||||
{
|
||||
uiaainfo.completed.push(AuthType::RegistrationToken);
|
||||
} else {
|
||||
uiaainfo.auth_error = Some(ruma::api::client::error::StandardErrorBody {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue