blob: f4522ed2091f392ef21cb4af23e7be48885d4d6f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
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();
}
}
|