diff --git a/Cargo.toml b/Cargo.toml index 4ae23b40..42d6fa66 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,6 +30,10 @@ version = "0.3.1" optional = true version = "0.2.2" +[dependencies.serde] +version = "1.0.87" +features = ["derive"] + [dev-dependencies] ruma-events = "0.11.0" tokio = "0.1" diff --git a/src/lib.rs b/src/lib.rs index 5be158c2..84ade332 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -114,7 +114,11 @@ where }, ) .map(move |response| { - let session = Session::new(response.access_token, response.user_id, response.device_id); + let session = Session { + access_token: response.access_token, + device_id: response.device_id, + user_id: response.user_id, + }; *data.session.lock().unwrap() = Some(session.clone()); session @@ -142,7 +146,11 @@ where }, ) .map(move |response| { - let session = Session::new(response.access_token, response.user_id, response.device_id); + let session = Session { + access_token: response.access_token, + device_id: response.device_id, + user_id: response.user_id, + }; *data.session.lock().unwrap() = Some(session.clone()); session @@ -179,7 +187,11 @@ where }, ) .map(move |response| { - let session = Session::new(response.access_token, response.user_id, response.device_id); + let session = Session { + access_token: response.access_token, + device_id: response.device_id, + user_id: response.user_id, + }; *data.session.lock().unwrap() = Some(session.clone()); session @@ -252,7 +264,7 @@ where if E::METADATA.requires_authentication { if let Some(ref session) = *data1.session.lock().unwrap() { url.query_pairs_mut() - .append_pair("access_token", session.access_token()); + .append_pair("access_token", &session.access_token); } else { return Err(Error::AuthenticationRequired); } diff --git a/src/session.rs b/src/session.rs index 07314d26..b22809df 100644 --- a/src/session.rs +++ b/src/session.rs @@ -1,18 +1,19 @@ use ruma_identifiers::UserId; /// A user session, containing an access token and information about the associated user account. -#[derive(Clone, Debug, Eq, Hash, PartialEq)] +#[derive(Clone, Debug, serde::Deserialize, Eq, Hash, PartialEq, serde::Serialize)] pub struct Session { /// The access token used for this session. - access_token: String, + pub access_token: String, /// The user the access token was issued for. - user_id: UserId, + pub user_id: UserId, /// The ID of the client device - device_id: String, + pub device_id: String, } impl Session { /// Create a new user session from an access token and a user ID. + #[deprecated] pub fn new(access_token: String, user_id: UserId, device_id: String) -> Self { Session { access_token, @@ -22,16 +23,19 @@ impl Session { } /// Get the access token associated with this session. + #[deprecated] pub fn access_token(&self) -> &str { &self.access_token } /// Get the ID of the user the session belongs to. + #[deprecated] pub fn user_id(&self) -> &UserId { &self.user_id } /// Get ID of the device the session belongs to. + #[deprecated] pub fn device_id(&self) -> &str { &self.device_id }