{"record":{"id":"c86663002d8a3b33","repo":"jdx/mise","slug":"github-oauth-token-is-not-cached-run-mise-token","errorCode":null,"errorMessage":"GitHub OAuth token is not cached. Run `mise token github --oauth` to authorize.","messagePattern":"GitHub OAuth token is not cached\\. Run `mise token github --oauth` to authorize\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/github/oauth.rs","lineNumber":278,"sourceCode":"        // even though the token is still time-valid.\n        let stale_access_token = req.force_refresh.then_some(cached.access_token.as_str());\n        match refresh_cached_token(&cache_key, stale_access_token).await {\n            Ok(Some(token)) => return Ok(token),\n            Ok(None) => {}\n            Err(err) => {\n                if req.warn_on_refresh_failure {\n                    log_refresh_error(&err);\n                } else {\n                    debug!(\"failed to refresh GitHub OAuth token for environment export: {err:#}\");\n                }\n            }\n        }\n        if !req.force_refresh && cached.expires_at > chrono::Utc::now() {\n            return Ok(cached.access_token);\n        }\n    }\n    if !req.allow_device_flow {\n        bail!(\"GitHub OAuth token is not cached. Run `mise token github --oauth` to authorize.\");\n    }\n\n    let device = create_device_code().await?;\n    print_device_instructions(&device);\n    let token = poll_access_token(&device).await?;\n    let cached = token_response_to_cache(token)?;\n    let access_token = cached.access_token.clone();\n    if let Err(err) = cache_token(cache_key, cached).await {\n        warn!(\"failed to cache GitHub OAuth token: {err:#}\");\n    }\n    Ok(access_token)\n}\n\nasync fn create_device_code() -> Result<DeviceCodeResponse> {\n    let settings = Settings::get();\n    let url = format!(\n        \"{}/device/code\",\n        settings.github.oauth_auth_url.trim_end_matches('/')","sourceCodeStart":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/github/oauth.rs#L260-L296","documentation":"GitHub OAuth tokens issued by the device flow are cached with an expiry. When a non-forced token request finds no cached token (or an expired one) and the caller did not allow the interactive device flow, mise fails with instructions to authorize first instead of hanging on an interactive prompt.","triggerScenarios":"Calling `mise token github` without `--oauth` (or `token_async` with `allow_device_flow=false`) when no valid cached token exists — first use, expired token, or cache cleared.","commonSituations":"CI/non-interactive environments where device flow can't run; token cache wiped (new HOME, `mise cache clear`); token expired after 8 hours; running a different command that needs the token without having authorized once.","solutions":["Run `mise token github --oauth` once interactively to complete the device flow and cache a token","In CI, provide a PAT via `GITHUB_TOKEN`/`MISE_GITHUB_TOKEN` instead of relying on the OAuth cache","If a token was authorized before, check that the cache file is readable and HOME is the same user","Use force_refresh via `mise token github --force` only after confirming the client id and host config are correct"],"exampleFix":"// before (non-interactive CI)\nmise token github\n// after: authorize once locally, or use a PAT in CI\nexport GITHUB_TOKEN=ghp_xxx  # or run `mise token github --oauth` locally","handlingStrategy":"fallback","validationCode":"test -n \"$GITHUB_TOKEN\" || mise token github --oauth  # ensure a token source exists before non-interactive use","typeGuard":null,"tryCatchPattern":"// run authorize flow on missing-token, then retry\nif let Err(e) = get_token(false).await {\n    if e.to_string().contains(\"not cached\") {\n        get_token(/* allow_device_flow */ true).await?;\n    } else { return Err(e); }\n}","preventionTips":["Run `mise token github --oauth` once on each machine before scripted use","Provide GITHUB_TOKEN/MISE_GITHUB_TOKEN in CI instead of the device flow","Re-authorize after cache clears or long expiry gaps"],"tags":["github","oauth","token","cache-miss"],"backgroundTag":"authentication-required","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"}