| 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(&endpoint, SessionConfig { native_http: true, ..SessionConfig::default() }).await.expect("browser"); |
| 10 | let client = reqwest::Client::new(); |
| 11 | let checks = [ |
| 12 | ("graph me", "https://graph.microsoft.com/v1.0/me?$select=id", Scope::new(GRAPH, "User.Read")), |
| 13 | ("chatsvc conversations", "https://teams.cloud.microsoft/api/chatsvc/emea/v1/users/ME/conversations?view=msnp24Equivalent&pageSize=1", Scope::new(IC3, "Teams.AccessAsUser.All")), |
| 14 | ("mt calendar", "https://teams.cloud.microsoft/api/mt/emea/v2.1/me/calendars/calendarView?startDate=2026-11-10T00:00:00Z&endDate=2026-11-11T00:00:00Z", Scope::new(SPACES, "user_impersonation")), |
| 15 | ]; |
| 16 | for (label, url, scope) in checks { |
| 17 | let page_status = page.send(Request::get(url), &scope).await.map(|response| response.status).unwrap_or_else(|error| match error { |
| 18 | session::Error::Api { status, .. } => status, |
| 19 | _ => 0, |
| 20 | }); |
| 21 | let session_status = native.send(Request::get(url), &scope).await.map(|response| response.status).unwrap_or_else(|error| match error { |
| 22 | session::Error::Api { status, .. } => status, |
| 23 | _ => 0, |
| 24 | }); |
| 25 | let raw_status = match page.run_with_token(App::Teams, &scope, "return token;", &json!({}), false).await { |
| 26 | Ok(serde_json::Value::String(token)) => client |
| 27 | .get(url) |
| 28 | .bearer_auth(token) |
| 29 | .header("Origin", "https://teams.cloud.microsoft") |
| 30 | .send() |
| 31 | .await |
| 32 | .map(|response| response.status().as_u16()) |
| 33 | .unwrap_or(0), |
| 34 | _ => 0, |
| 35 | }; |
| 36 | println!("{label}: page {page_status}, session native {session_status}, rust without cookies {raw_status}"); |
| 37 | } |
| 38 | } |