{"record":{"id":"df45321f049c27e5","repo":"jackwener/OpenCLI","slug":"creator-douyin-com","errorCode":null,"errorMessage":"creator.douyin.com","messagePattern":"creator\\.douyin\\.com","errorType":"exception","errorClass":"AuthRequiredError","httpStatus":null,"severity":"error","filePath":"clis/douyin/_shared/sts2.js","lineNumber":18,"sourceCode":"import { AuthRequiredError } from '@jackwener/opencli/errors';\nconst STS2_URL = 'https://creator.douyin.com/aweme/mid/video/sts2/?scene=web&aid=1128&cookie_enabled=true&device_platform=web';\n/**\n * Fetch STS2 temporary credentials from the creator center.\n * These are used to authenticate Node.js-side TOS multipart uploads.\n * Returns: { access_key_id, secret_access_key, session_token, expired_time }\n */\nexport async function getSts2Credentials(page) {\n    const js = `fetch(${JSON.stringify(STS2_URL)}, { credentials: 'include' }).then(r => r.json())`;\n    const res = await page.evaluate(js);\n    const credentials = (typeof res === 'object' &&\n        res !== null &&\n        'data' in res &&\n        res.data)\n        ? res.data\n        : res;\n    if (!credentials?.access_key_id) {\n        throw new AuthRequiredError('creator.douyin.com', 'STS2 credentials missing');\n    }\n    return credentials;\n}\n","sourceCodeStart":1,"sourceCodeEnd":22,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/douyin/_shared/sts2.js#L1-L22","documentation":"getSts2Credentials fetches temporary STS2 storage credentials from creator.douyin.com and throws AuthRequiredError when the response contains no access_key_id. The thrown message is just the host because AuthRequiredError keys on the site whose authentication is required. Without valid STS2 credentials, subsequent storage/upload operations cannot be signed.","triggerScenarios":"The STS2 credential API returns an empty/unshaped payload (res or res.data missing access_key_id) — typically when the browser session is logged out or the credential endpoint rejects the request.","commonSituations":"Expired creator.douyin.com session; risk-control interstitial returning an empty body; API shape change moving credentials elsewhere in the response; calling credentials fetch before completing login.","solutions":["Re-authenticate on creator.douyin.com (fresh login/cookies) and retry the credential fetch.","Log the raw STS2 response to check whether the shape changed (credentials nested differently).","Complete any captcha/risk-control challenge, then re-fetch credentials.","Ensure the STS2 endpoint URL is current if Douyin changed its internal API."],"exampleFix":"// before: assuming credentials always present\nconst sts = await getSts2Credentials(page);\nuploadWith(sts.access_key_id);\n// after\nlet sts;\ntry {\n  sts = await getSts2Credentials(page);\n} catch (e) {\n  if (e instanceof AuthRequiredError) await reloginCreatorDouyin();\n  sts = await getSts2Credentials(page);\n}","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"function hasSts2Creds(v: unknown): v is { access_key_id: string } & Record<string, unknown> {\n  return typeof v === 'object' && v !== null && 'access_key_id' in v && Boolean((v as any).access_key_id);\n}","tryCatchPattern":"import { AuthRequiredError } from './_shared/errors.js';\ntry {\n  const sts = await getSts2Credentials(page);\n} catch (e) {\n  if (e instanceof AuthRequiredError) {\n    await relogin('creator.douyin.com');\n    return getSts2Credentials(page);\n  }\n  throw e;\n}","preventionTips":["Confirm an authenticated creator.douyin.com session before fetching STS2 credentials","Re-fetch credentials per upload session; STS2 tokens are short-lived","Complete any captcha/risk-control challenge before storage operations","Log raw responses if the credential shape changes after Douyin updates"],"tags":["douyin","auth","sts2","credentials"],"backgroundTag":"auth-required-session-expired","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}