{"record":{"id":"4155620bce6ecba1","repo":"jdx/mise","slug":"github-device-authorization-expired","errorCode":null,"errorMessage":"GitHub device authorization expired","messagePattern":"GitHub device authorization expired","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/github/oauth.rs","lineNumber":329,"sourceCode":"        .error_for_status()?\n        .json::<DeviceCodeResponse>()\n        .await?)\n}\n\nasync fn poll_access_token(device: &DeviceCodeResponse) -> Result<TokenResponse> {\n    let settings = Settings::get();\n    let deadline = chrono::Utc::now() + chrono::Duration::seconds(device.expires_in as i64);\n    let mut interval = device.interval.max(1);\n    let url = format!(\n        \"{}/oauth/access_token\",\n        settings.github.oauth_auth_url.trim_end_matches('/')\n    );\n    let client_id = settings.github.oauth_client_id.trim();\n    let client = crate::http::HTTP.reqwest()?;\n\n    loop {\n        if chrono::Utc::now() >= deadline {\n            bail!(\"GitHub device authorization expired\");\n        }\n        tokio::time::sleep(Duration::from_secs(interval)).await;\n\n        let response = match client\n            .post(&url)\n            .header(\"Accept\", \"application/json\")\n            .form(&[\n                (\"client_id\", client_id),\n                (\"device_code\", device.device_code.as_str()),\n                (\"grant_type\", GRANT_DEVICE_CODE),\n            ])\n            .send()\n            .await\n            .and_then(|r| r.error_for_status())\n        {\n            Ok(resp) => match resp.json::<TokenResponse>().await {\n                Ok(body) => body,\n                Err(err) => {","sourceCodeStart":311,"sourceCodeEnd":347,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/github/oauth.rs#L311-L347","documentation":"During the OAuth device flow, GitHub issues a device code valid for a bounded window (typically ~15 minutes). `poll_access_token` loops until the deadline polling GitHub's token endpoint; if the deadline passes before the user completes authorization (and before any terminal error like `authorization_pending` expiry), mise aborts with this error.","triggerScenarios":"Running `mise token github --oauth` and not visiting https://github.com/login/device and entering the code before the device code expires; sleeping/suspending the machine past the deadline; very long interval waits after GitHub slows polling.","commonSituations":"User walked away mid-login; copied the code too late; network slowness caused missed polling window; GitHub returned slow_down intervals that consumed the validity window; headless session where the instructions were never seen.","solutions":["Re-run `mise token github --oauth` and complete the authorization promptly at https://github.com/login/device","Enter the one-time code immediately after it prints; do not wait between printing and entering","Avoid suspending the machine during the flow; keep the terminal open until authorization completes","If device flow is impractical, authenticate with a PAT via `GITHUB_TOKEN`/`MISE_GITHUB_TOKEN` instead"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if let Err(e) = authorize().await {\n    if e.to_string().contains(\"device authorization expired\") {\n        // restart the device flow; do not poll the same dead device code\n        authorize().await?;\n    } else { return Err(e); }\n}","preventionTips":["Complete the github.com/login/device step as soon as the code is printed","Keep the machine awake and the terminal open during the device flow","Use a PAT in headless or unattended environments to skip the device flow entirely"],"tags":["github","oauth","device-flow","timeout"],"backgroundTag":"request-timeout","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}