hive_client/client/authentication/
user.rs1use chrono::{DateTime, Utc};
2use std::fmt::Debug;
3use std::ops::Add;
4
5#[derive(Debug)]
6pub struct User {
8 pub(crate) username: String,
11 pub(crate) password: String,
12}
13
14impl User {
15 #[must_use]
16 pub fn new<'a>(username: &'a str, password: &'a str) -> Self {
21 Self {
22 username: username.into(),
23 password: password.into(),
24 }
25 }
26}
27
28#[derive(Debug, Clone)]
35pub struct TrustedDevice {
36 #[allow(missing_docs)]
37 pub device_group_key: String,
38
39 #[allow(missing_docs)]
40 pub device_key: String,
41
42 #[allow(missing_docs)]
43 pub device_password: String,
44}
45
46impl TrustedDevice {
47 #[must_use]
48 pub fn new<'a>(
61 device_password: &'a str,
62 device_group_key: &'a str,
63 device_key: &'a str,
64 ) -> Self {
65 Self {
66 device_password: device_password.into(),
67 device_group_key: device_group_key.into(),
68 device_key: device_key.into(),
69 }
70 }
71}
72
73#[derive(Debug)]
74pub struct UntrustedDevice {
75 pub device_group_key: String,
76 pub device_key: String,
77}
78
79impl UntrustedDevice {
80 #[must_use]
81 pub(crate) fn new<'a>(device_group_key: &'a str, device_key: &'a str) -> Self {
82 Self {
83 device_group_key: device_group_key.into(),
84 device_key: device_key.into(),
85 }
86 }
87}
88
89#[derive(Debug)]
90pub struct Tokens {
91 pub(crate) id_token: String,
92 pub(crate) access_token: String,
93 pub(crate) refresh_token: String,
94 pub(crate) expires_at: DateTime<Utc>,
95}
96
97impl Tokens {
98 #[must_use]
99 pub fn new(
100 id_token: String,
101 access_token: String,
102 refresh_token: String,
103 expires_in: i32,
104 ) -> Self {
105 Self {
106 id_token,
107 access_token,
108 refresh_token,
109 expires_at: Utc::now().add(chrono::Duration::seconds(i64::from(expires_in))),
110 }
111 }
112}