{"record":{"id":"ad128824bc71bb01","repo":"zeroclaw-labs/zeroclaw","slug":"ms365-client-credentials-token-request-failed-s","errorCode":null,"errorMessage":"ms365: client_credentials token request failed ({status})","messagePattern":"ms365: client_credentials token request failed \\((.+?)\\)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/zeroclaw-tools/src/microsoft365/auth.rs","lineNumber":174,"sourceCode":"                (\"grant_type\", \"client_credentials\"),\n                (\"client_id\", &self.config.client_id),\n                (\"client_secret\", client_secret),\n                (\"scope\", &scope),\n            ])\n            .send()\n            .await\n            .context(\"ms365: failed to request client_credentials token\")?;\n\n        if !resp.status().is_success() {\n            let status = resp.status();\n            let body = resp.text().await.unwrap_or_default();\n            ::zeroclaw_log::record!(\n                DEBUG,\n                ::zeroclaw_log::Event::new(module_path!(), ::zeroclaw_log::Action::Note)\n                    .with_attrs(::serde_json::json!({\"body\": body})),\n                \"ms365: client_credentials raw OAuth error\"\n            );\n            anyhow::bail!(\"ms365: client_credentials token request failed ({status})\");\n        }\n\n        let token_resp: TokenResponse = resp\n            .json()\n            .await\n            .context(\"ms365: failed to parse token response\")?;\n\n        Ok(CachedTokenState {\n            access_token: token_resp.access_token,\n            refresh_token: token_resp.refresh_token,\n            expires_at: chrono::Utc::now().timestamp() + token_resp.expires_in,\n        })\n    }\n\n    async fn device_code_flow(&self, client: &reqwest::Client) -> anyhow::Result<CachedTokenState> {\n        let device_code_url = format!(\n            \"https://login.microsoftonline.com/{}/oauth2/v2.0/devicecode\",\n            self.config.tenant_id","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/zeroclaw-labs/zeroclaw/blob/88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc/crates/zeroclaw-tools/src/microsoft365/auth.rs#L156-L192","documentation":"Error \"ms365: client_credentials token request failed ({status})\" thrown in zeroclaw-labs/zeroclaw.","triggerScenarios":"Thrown at crates/zeroclaw-tools/src/microsoft365/auth.rs:174 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify tenant ID, client ID, and client secret; check the token endpoint status."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc","analyzedAt":"2026-08-23T01:07:41.857Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}