Tencent Cloud Serverless Authentication Utility

2.0.1 · active · verified Wed Apr 22

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

const tencentAuth = require('serverless-tencent-auth-tool');

// In a Serverless Framework context (e.g., within a custom plugin or component):
async function authenticateTencentCloud(context) {
  const auth = new tencentAuth();

  // Mimic Serverless Framework's context object structure for credentials
  const mockContext = {
    credentials: {
      tencent: {
        SecretId: process.env.TENCENT_SECRET_ID ?? '',
        SecretKey: process.env.TENCENT_SECRET_KEY ?? '',
        Token: process.env.TENCENT_TOKEN ?? '' // Optional, for temporary credentials
      }
    },
    // Or if credentials are in instance state (e.g., after initial deployment)
    instance: {
      state: {
        status: {
          tencent: {
            SecretId: process.env.TENCENT_SECRET_ID ?? '',
            SecretKey: process.env.TENCENT_SECRET_KEY ?? ''
          }
        }
      }
    }
  };

  // Use provided context or mock if running standalone
  const actualContext = context || mockContext;

  // Perform authentication and update credentials
  actualContext.credentials.tencent = actualContext.credentials.tencent
    ? await auth.doAuth(actualContext.credentials.tencent)
    : await auth.doAuth(actualContext.instance.state.status.tencent);

  console.log('Tencent Cloud credentials updated:', actualContext.credentials.tencent);
  return actualContext.credentials.tencent;
}

// Example usage (replace with your actual Serverless Framework context)
authenticateTencentCloud(null).catch(console.error);

view raw JSON →