From 00675738a4012580c6db10d9e1115732559bdaf3 Mon Sep 17 00:00:00 2001 From: bigfoot547 Date: Wed, 29 Jan 2025 03:27:31 -0600 Subject: do device code auth --- src/auth.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/auth.rs') diff --git a/src/auth.rs b/src/auth.rs index f4522ed..e7d8061 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -1,5 +1,5 @@ mod types; -pub mod device_code; +mod oauth; use std::error::Error; use std::fmt::{Display, Formatter}; @@ -9,12 +9,16 @@ pub use types::*; #[derive(Debug)] pub enum AuthError { Request { what: &'static str, error: reqwest::Error }, + Internal(String), + Timeout } 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) + AuthError::Request { what, error } => write!(f, "auth request error ({}): {}", what, error), + AuthError::Internal(msg) => write!(f, "internal auth error: {}", msg), + AuthError::Timeout => f.write_str("interactive authentication timed out") } } } @@ -22,7 +26,8 @@ impl Display for AuthError { impl Error for AuthError { fn source(&self) -> Option<&(dyn Error + 'static)> { match self { - AuthError::Request { error, .. } => Some(error) + AuthError::Request { error, .. } => Some(error), + _ => None } } } @@ -42,14 +47,18 @@ impl MsaUser { #[cfg(test)] mod test { use reqwest::Client; + use crate::auth::oauth::device_code; use super::*; #[tokio::test] async fn abc() { - device_code::DeviceCodeAuthBuilder::new() + simple_logger::SimpleLogger::new().with_colors(true).with_level(log::LevelFilter::Trace).init().unwrap(); + + _=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(); + .add_scope("service::user.auth.xboxlive.com::MBI_SSL", true) + .code_request_url("https://login.live.com/oauth20_connect.srf") + .check_url("https://login.live.com/oauth20_token.srf") + .begin(Client::new()).await.unwrap().drive().await; } } -- cgit v1.2.3-70-g09d2