{"id":16745,"library":"serverless-tencent-auth-tool","title":"Tencent Cloud Serverless Authentication Utility","description":"This package, `serverless-tencent-auth-tool`, simplifies authentication and credential management for applications deployed on Tencent Cloud's Serverless Framework. It streamlines processes such as automatic login, obtaining Tencent Cloud AppIds, and verifying real-name authentication status, which are critical for operating services within the Chinese cloud ecosystem. As of version 2.0.1, it provides a utility class to interact with Tencent Cloud's authentication mechanisms from within a Serverless environment. While a specific release cadence isn't clearly documented, the version number indicates active development. It serves as a practical tool for developers to integrate Tencent Cloud's strict identity and access management requirements into their serverless applications, differentiating itself by abstracting complex auth flows.","status":"active","version":"2.0.1","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","Tencent Cloud","Serverless Framework","Cloud function"],"install":[{"cmd":"npm install serverless-tencent-auth-tool","lang":"bash","label":"npm"},{"cmd":"yarn add serverless-tencent-auth-tool","lang":"bash","label":"yarn"},{"cmd":"pnpm add serverless-tencent-auth-tool","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The primary usage shown in documentation is CommonJS `require()`. While ESM import `import tencentAuth from 'pkg'` might work if there's a default export, named imports are incorrect for this pattern.","wrong":"import { tencentAuth } from 'serverless-tencent-auth-tool';","symbol":"tencentAuth","correct":"const tencentAuth = require('serverless-tencent-auth-tool');"},{"note":"The module exports a class or constructor function that must be instantiated before calling methods like `doAuth`.","wrong":"tencentAuth.doAuth(...);","symbol":"TencentAuthClassInstance","correct":"const auth = new tencentAuth();"}],"quickstart":{"code":"const tencentAuth = require('serverless-tencent-auth-tool');\n\n// In a Serverless Framework context (e.g., within a custom plugin or component):\nasync function authenticateTencentCloud(context) {\n  const auth = new tencentAuth();\n\n  // Mimic Serverless Framework's context object structure for credentials\n  const mockContext = {\n    credentials: {\n      tencent: {\n        SecretId: process.env.TENCENT_SECRET_ID ?? '',\n        SecretKey: process.env.TENCENT_SECRET_KEY ?? '',\n        Token: process.env.TENCENT_TOKEN ?? '' // Optional, for temporary credentials\n      }\n    },\n    // Or if credentials are in instance state (e.g., after initial deployment)\n    instance: {\n      state: {\n        status: {\n          tencent: {\n            SecretId: process.env.TENCENT_SECRET_ID ?? '',\n            SecretKey: process.env.TENCENT_SECRET_KEY ?? ''\n          }\n        }\n      }\n    }\n  };\n\n  // Use provided context or mock if running standalone\n  const actualContext = context || mockContext;\n\n  // Perform authentication and update credentials\n  actualContext.credentials.tencent = actualContext.credentials.tencent\n    ? await auth.doAuth(actualContext.credentials.tencent)\n    : await auth.doAuth(actualContext.instance.state.status.tencent);\n\n  console.log('Tencent Cloud credentials updated:', actualContext.credentials.tencent);\n  return actualContext.credentials.tencent;\n}\n\n// Example usage (replace with your actual Serverless Framework context)\nauthenticateTencentCloud(null).catch(console.error);","lang":"javascript","description":"Demonstrates how to import the `tencentAuth` class, instantiate it, and use `doAuth` to manage Tencent Cloud credentials within a Serverless Framework context, including placeholders for environment variables."},"warnings":[{"fix":"Consult the `serverless` and `tencentcloud-sdk-nodejs` official documentation for migration guides related to authentication and API changes.","message":"Breaking changes for this specific utility between major versions are not explicitly documented. However, general Tencent Cloud SDKs and the Serverless Framework itself undergo significant updates. Always review the `serverless` CLI and `tencentcloud-sdk-nodejs` release notes when upgrading to avoid compatibility issues.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Ensure the Tencent Cloud account linked to your credentials has completed real-name verification via the Tencent Cloud Console. This is a manual, out-of-band process.","message":"Tencent Cloud's stringent real-name verification (实名认证) is mandatory for many services, especially for accounts in mainland China. Operations will fail if the account has not completed this process. This tool can detect if it's done, but cannot complete it.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Use the primary (root) Tencent Cloud account to execute initial authorization commands (e.g., `serverless tencent initcam`) or explicitly grant `SCF_QcsRole` and other required permissions to the sub-account through Tencent Cloud's CAM console.","message":"Sub-accounts often lack the necessary permissions for initial setup, role creation, or accessing certain resources. This can lead to `UnauthorizedOperation` errors even with correct `SecretId` and `SecretKey`.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Provide the `tencent_app_id` in your Serverless configuration or ensure it's available in your credential context if your application uses features requiring it. It can be found in the Tencent Cloud Account Center.","message":"The `APPID` (AppId) is crucial for certain Tencent Cloud services and features, particularly for package deployments larger than 10MB (which use COS for upload) or specific API Gateway configurations. Omitting it can cause deployment failures.","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Log in to the Tencent Cloud console and complete the real-name verification process for your account.","cause":"The Tencent Cloud account has not completed identity (real-name) verification, which is a prerequisite for many services.","error":"UnauthorizedOperation.NonAuthorize"},{"fix":"Verify the IAM policies associated with your credentials in the Tencent Cloud CAM console. Grant the required permissions (e.g., `SCFFullAccess` or specific service permissions) to the user or role.","cause":"The provided `SecretId` and `SecretKey` belong to an account or sub-account that lacks the necessary permissions to perform the requested operation.","error":"UnauthorizedOperation"},{"fix":"Double-check your credential configuration in `serverless.yml`, environment variables, or `this.context.credentials` to ensure all required fields are present and correctly formatted. Pay attention to whitespace.","cause":"One or more authentication parameters (e.g., `SecretId`, `SecretKey`, `Token`, `Region`) are missing, incorrectly formatted, or invalid.","error":"InvalidParameter"},{"fix":"Recharge your Tencent Cloud account to ensure a positive balance and resolve any overdue payments.","cause":"The Tencent Cloud account has overdue payments or an insufficient balance, which prevents resource operations.","error":"FailedOperation.AccountArrears"}],"ecosystem":"npm"}