summaryrefslogtreecommitdiffstats
path: root/src/auth.rs
diff options
context:
space:
mode:
authorLibravatar bigfoot547 <[email protected]>2025-01-28 21:23:07 -0600
committerLibravatar bigfoot547 <[email protected]>2025-01-28 21:23:07 -0600
commitdc3917b05018cb32e2451d9eaed242036c5e7512 (patch)
treef697a64acf2eb5d7d2419d9ca3b97be05f9067ee /src/auth.rs
parentinteractive auth testing (diff)
wip: auth
Diffstat (limited to 'src/auth.rs')
-rw-r--r--src/auth.rs54
1 files changed, 53 insertions, 1 deletions
diff --git a/src/auth.rs b/src/auth.rs
index a11c0de..f4522ed 100644
--- a/src/auth.rs
+++ b/src/auth.rs
@@ -1,3 +1,55 @@
-struct AuthenticationDatabase {
+mod types;
+pub mod device_code;
+use std::error::Error;
+use std::fmt::{Display, Formatter};
+use chrono::{DateTime, Utc};
+pub use types::*;
+
+#[derive(Debug)]
+pub enum AuthError {
+ Request { what: &'static str, error: reqwest::Error },
+}
+
+impl Display for AuthError {
+ fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
+ match self {
+ AuthError::Request { what, error } => write!(f, "auth request error ({}): {}", what, error)
+ }
+ }
+}
+
+impl Error for AuthError {
+ fn source(&self) -> Option<&(dyn Error + 'static)> {
+ match self {
+ AuthError::Request { error, .. } => Some(error)
+ }
+ }
+}
+
+impl Token {
+ fn is_expired(&self, now: DateTime<Utc>) -> bool {
+ self.expire.is_some_and(|exp| now < exp)
+ }
+}
+
+impl MsaUser {
+ async fn log_in(&mut self) -> Result<(), AuthError> {
+ todo!()
+ }
+}
+
+#[cfg(test)]
+mod test {
+ use reqwest::Client;
+ use super::*;
+
+ #[tokio::test]
+ async fn abc() {
+ device_code::DeviceCodeAuthBuilder::new()
+ .client_id("00000000402b5328")
+ .scope("service::user.auth.xboxlive.com::MBI_SSL")
+ .url("https://login.live.com/oauth20_connect.srf")
+ .begin(Client::new()).await.unwrap();
+ }
}