aboutsummaryrefslogtreecommitdiff
path: root/client/src/lib.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2023-12-11 01:19:51 +0100
committermetamuffin <metamuffin@disroot.org>2023-12-11 01:19:51 +0100
commit36d7fb2790774c53415c96f8c6955be42bad952f (patch)
tree4481dac53a6d0896e90ff72b9b68665e59e159db /client/src/lib.rs
parent767d6c4c7b8518198b0343781128027051b94ae5 (diff)
downloadjellything-36d7fb2790774c53415c96f8c6955be42bad952f.tar
jellything-36d7fb2790774c53415c96f8c6955be42bad952f.tar.bz2
jellything-36d7fb2790774c53415c96f8c6955be42bad952f.tar.zst
(partially) fix security problem with federated session
Diffstat (limited to 'client/src/lib.rs')
-rw-r--r--client/src/lib.rs26
1 files changed, 13 insertions, 13 deletions
diff --git a/client/src/lib.rs b/client/src/lib.rs
index 92545a9..eca27fc 100644
--- a/client/src/lib.rs
+++ b/client/src/lib.rs
@@ -4,13 +4,14 @@
Copyright (C) 2023 metamuffin <metamuffin.org>
*/
use anyhow::Result;
+use jellycommon::user::UserPermission;
use log::debug;
use reqwest::{
header::{HeaderMap, HeaderValue},
Client,
};
-use serde_json::json;
-use std::time::Duration;
+use serde::Serialize;
+use std::collections::HashSet;
use stream::StreamSpec;
use tokio::io::AsyncWriteExt;
@@ -22,6 +23,14 @@ pub struct Instance {
pub tls: bool,
}
+#[derive(Serialize)]
+pub struct LoginDetails {
+ pub username: String,
+ pub password: String,
+ pub expire: Option<i64>,
+ pub drop_permissions: Option<HashSet<UserPermission>>,
+}
+
impl Instance {
pub fn new(host: String, tls: bool) -> Self {
Self { host, tls }
@@ -33,20 +42,11 @@ impl Instance {
self.host
)
}
- pub async fn login(
- self,
- username: String,
- password: String,
- expire: Duration,
- ) -> anyhow::Result<Session> {
+ pub async fn login(self, data: LoginDetails) -> anyhow::Result<Session> {
let session_token = Client::builder()
.build()?
.post(format!("{}/api/create_session", self.base()))
- .json(&json!({
- "expire": expire.as_secs(),
- "password": password,
- "username": username,
- }))
+ .json(&data)
.send()
.await?
.json()