| 1 | //! Read-only: the same GETs once through the page and once from Rust with the page's token (no cookies). Prints status codes only. |
| 2 | use serde_json::json; |
| 3 | use session::{App, DEFAULT_ENDPOINT, GRAPH, IC3, Request, SPACES, Scope, Session, SessionConfig}; |
| 4 | |
| 5 | #[tokio::main] |
| 6 | async fn main() { |
| 7 | let endpoint = std::env::var("CDP_ENDPOINT").unwrap_or_else(|_| DEFAULT_ENDPOINT.to_owned()); |
| 8 | let page = Session::connect(&endpoint).await.expect("browser"); |
| 9 | let native = Session::connect_with( |
| 10 | &endpoint, |
| 11 | SessionConfig { |
| 12 | native_http: true, |
| 13 | ..SessionConfig::default() |
| 14 | }, |
| 15 | ) |
| 16 | .await |
| 17 | .expect("browser"); |
| 18 | let client = reqwest::Client::new(); |
| 19 | let checks = [ |
| 20 | ( |
| 21 | "graph me", |
| 22 | "https://graph.microsoft.com/v1.0/me?$select=id", |
| 23 | Scope::new(GRAPH, "User.Read"), |
| 24 | ), |
| 25 | ( |
| 26 | "chatsvc conversations", |
| 27 | "https://teams.cloud.microsoft/api/chatsvc/emea/v1/users/ME/conversations?view=msnp24Equivalent&pageSize=1", |
| 28 | Scope::new(IC3, "Teams.AccessAsUser.All"), |
| 29 | ), |
| 30 | ( |
| 31 | "mt calendar", |
| 32 | "https://teams.cloud.microsoft/api/mt/emea/v2.1/me/calendars/calendarView?startDate=2026-11-10T00:00:00Z&endDate=2026-11-11T00:00:00Z", |
| 33 | Scope::new(SPACES, "user_impersonation"), |
| 34 | ), |
| 35 | ]; |
| 36 | for (label, url, scope) in checks { |
| 37 | let page_status = page |
| 38 | .send(Request::get(url), &scope) |
| 39 | .await |
| 40 | .map(|response| response.status) |
| 41 | .unwrap_or_else(|error| match error { |
| 42 | session::Error::Api { status, .. } => status, |
| 43 | _ => 0, |
| 44 | }); |
| 45 | let session_status = native |
| 46 | .send(Request::get(url), &scope) |
| 47 | .await |
| 48 | .map(|response| response.status) |
| 49 | .unwrap_or_else(|error| match error { |
| 50 | session::Error::Api { status, .. } => status, |
| 51 | _ => 0, |
| 52 | }); |
| 53 | let raw_status = match page |
| 54 | .run_with_token(App::Teams, &scope, "return token;", &json!({}), false) |
| 55 | .await |
| 56 | { |
| 57 | Ok(serde_json::Value::String(token)) => client |
| 58 | .get(url) |
| 59 | .bearer_auth(token) |
| 60 | .header("Origin", "https://teams.cloud.microsoft") |
| 61 | .send() |
| 62 | .await |
| 63 | .map(|response| response.status().as_u16()) |
| 64 | .unwrap_or(0), |
| 65 | _ => 0, |
| 66 | }; |
| 67 | println!( |
| 68 | "{label}: page {page_status}, session native {session_status}, rust without cookies {raw_status}" |
| 69 | ); |
| 70 | } |
| 71 | } |