hive_client/client/authentication/
user.rs1use chrono::{DateTime, Utc};
2use std::fmt::Debug;
3use std::ops::Add;
4use std::sync::Arc;
5
6#[derive(Debug)]
7pub struct User {
9 pub(crate) username: String,
12 pub(crate) password: String,
13 pub(crate) device: Option<Arc<TrustedDevice>>,
14}
15
16impl User {
17 #[must_use]
18 pub fn new<'a>(
23 username: &'a str,
24 password: &'a str,
25 trusted_device: Option<TrustedDevice>,
26 ) -> Self {
27 Self {
28 username: username.into(),
29 password: password.into(),
30 device: trusted_device.map(Arc::new),
31 }
32 }
33}
34
35#[derive(Debug)]
36pub enum AuthDevice {
37 Trusted(Arc<TrustedDevice>),
38 Untrusted(UntrustedDevice),
39}
40
41#[derive(Debug, Clone)]
48pub struct TrustedDevice {
49 #[allow(missing_docs)]
50 pub device_group_key: String,
51
52 #[allow(missing_docs)]
53 pub device_key: String,
54
55 #[allow(missing_docs)]
56 pub device_password: String,
57}
58
59impl TrustedDevice {
60 #[must_use]
61 pub fn new<'a>(
81 device_password: &'a str,
82 device_group_key: &'a str,
83 device_key: &'a str,
84 ) -> Self {
85 Self {
86 device_password: device_password.into(),
87 device_group_key: device_group_key.into(),
88 device_key: device_key.into(),
89 }
90 }
91}
92
93#[derive(Debug)]
94pub struct UntrustedDevice {
95 pub device_group_key: String,
96 pub device_key: String,
97}
98
99impl UntrustedDevice {
100 #[must_use]
101 pub(crate) fn new<'a>(device_group_key: &'a str, device_key: &'a str) -> Self {
102 Self {
103 device_group_key: device_group_key.into(),
104 device_key: device_key.into(),
105 }
106 }
107}
108
109#[derive(Debug)]
110pub struct Tokens {
111 pub(crate) id_token: String,
112 pub(crate) access_token: String,
113 pub(crate) refresh_token: String,
114 pub(crate) expires_at: DateTime<Utc>,
115}
116
117impl Tokens {
118 #[must_use]
119 pub fn new(
120 id_token: String,
121 access_token: String,
122 refresh_token: String,
123 expires_in: i32,
124 ) -> Self {
125 Self {
126 id_token,
127 access_token,
128 refresh_token,
129 expires_at: Utc::now().add(chrono::Duration::seconds(i64::from(expires_in))),
130 }
131 }
132}