The device_id is needed by the client, but otherwise inaccessible (unless provided to the server by the client). This is analogous to how the user_id is currently stored for guests, but will probably be more often used. The device_id is needed to implement e2e encryption.
39 lines
1.0 KiB
Rust
39 lines
1.0 KiB
Rust
use ruma_identifiers::UserId;
|
|
|
|
/// A user session, containing an access token and information about the associated user account.
|
|
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
|
pub struct Session {
|
|
/// The access token used for this session.
|
|
access_token: String,
|
|
/// The user the access token was issued for.
|
|
user_id: UserId,
|
|
/// The ID of the client device
|
|
device_id: String,
|
|
}
|
|
|
|
impl Session {
|
|
/// Create a new user session from an access token and a user ID.
|
|
pub fn new(access_token: String, user_id: UserId, device_id: String) -> Self {
|
|
Session {
|
|
access_token,
|
|
user_id,
|
|
device_id,
|
|
}
|
|
}
|
|
|
|
/// Get the access token associated with this session.
|
|
pub fn access_token(&self) -> &str {
|
|
&self.access_token
|
|
}
|
|
|
|
/// Get the ID of the user the session belongs to.
|
|
pub fn user_id(&self) -> &UserId {
|
|
&self.user_id
|
|
}
|
|
|
|
/// Get ID of the device the session belongs to.
|
|
pub fn device_id(&self) -> &str {
|
|
&self.device_id
|
|
}
|
|
}
|