Make Session fields public.
This commit is contained in:
parent
c50f043c51
commit
fa798d7a04
@ -30,6 +30,10 @@ version = "0.3.1"
|
|||||||
optional = true
|
optional = true
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
|
|
||||||
|
[dependencies.serde]
|
||||||
|
version = "1.0.87"
|
||||||
|
features = ["derive"]
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
ruma-events = "0.11.0"
|
ruma-events = "0.11.0"
|
||||||
tokio = "0.1"
|
tokio = "0.1"
|
||||||
|
20
src/lib.rs
20
src/lib.rs
@ -114,7 +114,11 @@ where
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
.map(move |response| {
|
.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());
|
*data.session.lock().unwrap() = Some(session.clone());
|
||||||
|
|
||||||
session
|
session
|
||||||
@ -142,7 +146,11 @@ where
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
.map(move |response| {
|
.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());
|
*data.session.lock().unwrap() = Some(session.clone());
|
||||||
|
|
||||||
session
|
session
|
||||||
@ -179,7 +187,11 @@ where
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
.map(move |response| {
|
.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());
|
*data.session.lock().unwrap() = Some(session.clone());
|
||||||
|
|
||||||
session
|
session
|
||||||
@ -252,7 +264,7 @@ where
|
|||||||
if E::METADATA.requires_authentication {
|
if E::METADATA.requires_authentication {
|
||||||
if let Some(ref session) = *data1.session.lock().unwrap() {
|
if let Some(ref session) = *data1.session.lock().unwrap() {
|
||||||
url.query_pairs_mut()
|
url.query_pairs_mut()
|
||||||
.append_pair("access_token", session.access_token());
|
.append_pair("access_token", &session.access_token);
|
||||||
} else {
|
} else {
|
||||||
return Err(Error::AuthenticationRequired);
|
return Err(Error::AuthenticationRequired);
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
use ruma_identifiers::UserId;
|
use ruma_identifiers::UserId;
|
||||||
|
|
||||||
/// A user session, containing an access token and information about the associated user account.
|
/// 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 {
|
pub struct Session {
|
||||||
/// The access token used for this session.
|
/// The access token used for this session.
|
||||||
access_token: String,
|
pub access_token: String,
|
||||||
/// The user the access token was issued for.
|
/// The user the access token was issued for.
|
||||||
user_id: UserId,
|
pub user_id: UserId,
|
||||||
/// The ID of the client device
|
/// The ID of the client device
|
||||||
device_id: String,
|
pub device_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Session {
|
impl Session {
|
||||||
/// Create a new user session from an access token and a user ID.
|
/// 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 {
|
pub fn new(access_token: String, user_id: UserId, device_id: String) -> Self {
|
||||||
Session {
|
Session {
|
||||||
access_token,
|
access_token,
|
||||||
@ -22,16 +23,19 @@ impl Session {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the access token associated with this session.
|
/// Get the access token associated with this session.
|
||||||
|
#[deprecated]
|
||||||
pub fn access_token(&self) -> &str {
|
pub fn access_token(&self) -> &str {
|
||||||
&self.access_token
|
&self.access_token
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the ID of the user the session belongs to.
|
/// Get the ID of the user the session belongs to.
|
||||||
|
#[deprecated]
|
||||||
pub fn user_id(&self) -> &UserId {
|
pub fn user_id(&self) -> &UserId {
|
||||||
&self.user_id
|
&self.user_id
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get ID of the device the session belongs to.
|
/// Get ID of the device the session belongs to.
|
||||||
|
#[deprecated]
|
||||||
pub fn device_id(&self) -> &str {
|
pub fn device_id(&self) -> &str {
|
||||||
&self.device_id
|
&self.device_id
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user