Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问clear审计通过

auth-nodejs-cloudbaseauth Node.js cloudbase 搜索

Agent Skill

用于辅助安全审计、权限检查、凭据风险、认证流程和常见漏洞排查。它适合让 Agent 梳理敏感配置、检查依赖风险、分析鉴权逻辑或生成安全复核清单。使用时不能把工具输出直接当最终结论,涉及密钥、令牌、用户数据或生产系统时,应先确认最小权限、脱敏方式和操作边界。

总安装

16,824

周安装

701

GitHub Stars

51

下载量

5,608
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

3

许可证

MIT

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:auth-nodejs-cloudbase(auth Node.js cloudbase 搜索)
来源仓库:https://github.com/tencentcloudbase/skills
仓库路径:skills/auth-nodejs-cloudbase
安装命令:
npx skills add https://github.com/tencentcloudbase/skills --skill auth-nodejs-cloudbase
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/tencentcloudbase/skills --skill auth-nodejs-cloudbase

简介

CloudBase Node.js 后端和云功能的服务器端身份和用户查找。

  • 检索呼叫者身份( uid, 自定义用户ID, 开放ID) 在云函数中使用 getUserInfo()
  • 用于授权和个性化决策。
  • 通过uid查询CloudBase用户资料
  • 或使用 getEndUserInfo() 的登录标识符(电话、电子邮件、用户名、自定义 ID)
  • 和 queryUserInfo()
  • 从 Node 后端发出自定义登录票证,将现有用户系统桥接到 CloudBase,无需单独的注册流程。
  • 捕获客户端 IP 地址以在云功能环境中进行审核日志记录和安全检查。

SKILL.md

Standalone Install Note

If this environment only installed the current skill, start from the CloudBase main entry and use the published cloudbase/references/... paths for sibling skills.

  • CloudBase main entry: https://cnb.cool/tencent/cloud/cloudbase/cloudbase-skills/-/git/raw/main/skills/cloudbase/SKILL.md
  • Current skill raw source: https://cnb.cool/tencent/cloud/cloudbase/cloudbase-skills/-/git/raw/main/skills/cloudbase/references/auth-nodejs/SKILL.md

Keep local references/... paths for files that ship with the current skill directory. When this file points to a sibling skill such as auth-tool or web-development, use the standalone fallback URL shown next to that reference.

Activation Contract

Use this first when

  • Node.js code in cloud functions or backend services must read caller identity, look up users, or issue custom login tickets.
  • The backend responsibility is auth / identity, not provider setup or frontend login UI.

Read before writing code if

  • The task mentions @cloudbase/node-sdk, server-side auth, custom login tickets, or "who is calling".
  • The request mixes frontend login with backend identity logic; split the flow and route client-side work elsewhere.

Then also read

  • Provider setup / publishable key -> ../auth-tool/SKILL.md (standalone fallback: https://cnb.cool/tencent/cloud/cloudbase/cloudbase-skills/-/git/raw/main/skills/cloudbase/references/auth-tool/SKILL.md)
  • Web login UI that consumes custom tickets -> ../auth-web/SKILL.md (standalone fallback: https://cnb.cool/tencent/cloud/cloudbase/cloudbase-skills/-/git/raw/main/skills/cloudbase/references/auth-web/SKILL.md)
  • Raw HTTP auth client -> ../http-api/SKILL.md (standalone fallback: https://cnb.cool/tencent/cloud/cloudbase/cloudbase-skills/-/git/raw/main/skills/cloudbase/references/http-api/SKILL.md)

Do NOT use for

  • Provider enable/disable or login console configuration.
  • Frontend login / sign-up UI.
  • Mini program native auth.

Common mistakes / gotchas

  • Using this skill as the entry point for every auth request.
  • Mixing provider-management work with Node-side identity code.
  • Reaching for raw HTTP examples when Node SDK already covers the job.

When to use this skill

Use this skill whenever the task involves server-side authentication or identity in a CloudBase project, and the code is running in Node.js, for example:

  • CloudBase 云函数 (Node runtime) that needs to know who is calling
  • Node services that use CloudBase Node SDK to look up user information
  • Backends that issue custom login tickets for Web / mobile clients
  • Admin or ops tools that need to inspect CloudBase end-user profiles

Do NOT use this skill for:

  • Frontend Web login / sign-up flows using @cloudbase/js-sdk (handle those with the auth-web skill, not this Node skill).
  • Direct HTTP auth API integrations (this skill does not describe raw HTTP endpoints; use the http-api skill instead).
  • Database or storage operations that do not involve identity (use database/storage docs or skills).

When the user request mixes frontend and backend concerns (e.g. "build a web login page and a Node API that knows the user"), treat them separately:

  • Use Web-side auth docs/skills for client login and UX.
  • Use this Node Auth skill for how the backend sees and uses the authenticated user.

How to use this skill (for a coding agent)

When you load this skill to work on a task:

  1. Clarify the runtime and responsibility Ask the user:

- Where does this Node code run? - CloudBase 云函数 - Long‑running Node service using CloudBase - What do they need from auth? - Just the caller identity for authorization? - Look up arbitrary users by UID / login identifier? - Bridge their own user system into CloudBase via custom login?

  1. Confirm CloudBase environment and SDK import tcb from "@cloudbase/node-sdk"; const app = tcb.init({env: "your-env-id"}); const auth = app.auth();

- Ask for: - env – CloudBase environment ID - Install the latest @cloudbase/node-sdk from npm if it is not already available. - Always initialize the SDK using this pattern (values can change, shape must not):

  1. Pick the relevant scenario from this file

- For caller identity inside a function, use the getUserInfo scenarios. - For full user profile or admin lookup, use the getEndUserInfo and queryUserInfo scenarios. - For client systems that already have their own users, use the custom login ticket scenarios built on createTicket. - For logging / security, use the getClientIP scenario.

  1. Follow Node SDK API shapes exactly

- Treat all auth.* methods and parameter shapes in this file as canonical. - You may change variable names and framework (e.g. Express vs 云函数 handler), but do not change SDK method names or parameter fields. - If you see a method in older code that is not listed here or in the Node SDK docs mirror, treat it as suspect and avoid using it.

  1. If you are unsure about an API

- Consult the official CloudBase Auth Node SDK documentation. - Only use methods and shapes that appear in the official documentation. - If you cannot find an API you want: - Prefer composing flows from the documented methods, or - Explain that this skill only covers Node SDK auth, and suggest using the relevant CloudBase Web or HTTP auth documentation for client-side or raw-HTTP flows.


Node auth architecture – how Node fits into CloudBase Auth

CloudBase Auth v2 separates where users log in from where backend code runs:

  • Users log in through the supported auth methods (anonymous, username/password, SMS, email, WeChat, custom login, etc.) using client SDKs or HTTP interfaces, as described in the official CloudBase Auth overview documentation.
  • Once logged in, CloudBase attaches the user identity and tokens to the environment.
  • Node code then reads that identity using the Node SDK, or bridges external identities into CloudBase using custom login.

In practice, Node code usually does one or more of:

  1. Identify the current caller

- In 云函数, use auth.getUserInfo() to read uid, openId, and customUserId. - Use this identity for authorization decisions, logging, and personalisation.

  1. Look up other users

- Use auth.getEndUserInfo(uid) when you know the CloudBase uid. - Use auth.queryUserInfo({platform, platformId, uid?}) when you only have login identifiers such as phone, email, username, or a custom ID.

  1. Issue custom login tickets

- When you already have your own user system, your Node backend can call auth.createTicket(customUserId, options) and return the ticket to a trusted client. - The client (typically Web) then uses this ticket with the Web SDK to log the user into CloudBase without forcing them to sign up again.

  1. Log client IP for security

- In 云函数, auth.getClientIP() returns the caller IP, which you can use for audit logs, anomaly detection, or access control.

The scenarios later in this file turn these responsibilities into explicit, copy‑pasteable patterns.


Node Auth APIs covered by this skill

This skill covers the following auth methods on the CloudBase Node SDK. Treat these method signatures as the only supported entry points for Node auth flows when using this skill:

  • getUserInfo(): IGetUserInfoResult Returns {openId, appId, uid, customUserId} for the current caller.
  • getEndUserInfo(uid?: string, opts?: ICustomReqOpts): Promise<{userInfo: EndUserInfo; requestId?: string}> Returns detailed CloudBase end‑user profile for a given uid or for the current caller (when uid is omitted).
  • queryUserInfo(query: IUserInfoQuery, opts?: ICustomReqOpts): Promise<{userInfo: EndUserInfo; requestId?: string}> Finds a user by login identifier (platform + platformId) or uid.
  • getClientIP(): string Returns the caller’s IP address when running in a supported environment (e.g. 云函数).
  • createTicket(customUserId: string, options?: ICreateTicketOpts): string Creates a custom login ticket for the given customUserId that clients can exchange for a CloudBase login.

The exact field names and allowed values for EndUserInfo, IUserInfoQuery, and ICreateTicketOpts are defined by the official CloudBase Node SDK typings and documentation. When writing Node code, do not guess shapes; follow the SDK types and the examples in this file.


Scenarios – Node auth patterns

Scenario 1: Initialize Node SDK and auth in a CloudBase function

Use this when writing a CloudBase 云函数 that needs to interact with Auth:

import tcb from "@cloudbase/node-sdk";

const app = tcb.init({ env: "your-env-id" });
const auth = app.auth();

exports.main = async (event, context) => {
  // Your logic here
};

Key points:

  • Use the same env as configured for the function’s CloudBase 环境.
  • Avoid hardcoding sensitive values; prefer environment variables or function configuration.

Scenario 2: Get caller identity in a CloudBase function

Use this when you need to know who is calling your cloud function:

import tcb from "@cloudbase/node-sdk";

const app = tcb.init({ env: "your-env-id" });
const auth = app.auth();

exports.main = async (event, context) => {
  const { openId, appId, uid, customUserId } = auth.getUserInfo();

  console.log("Caller identity", { openId, appId, uid, customUserId });

  // Use uid / customUserId for authorization decisions
  // e.g. check roles, permissions, or data ownership
};

Best practices:

  • Treat uid as the canonical CloudBase user identifier.
  • Use customUserId only when you have enabled 自定义登录 and mapped your own users.
  • Never trust openId/appId alone for authorization; they are WeChat‑specific identifiers.

Scenario 3: Get full end‑user profile by UID

Use this when you know a user’s CloudBase uid (for example, from a database record) and you need detailed profile information:

import tcb from "@cloudbase/node-sdk";

const app = tcb.init({ env: "your-env-id" });
const auth = app.auth();

exports.main = async (event, context) => {
  const uid = "user-uid";

  try {
    const { userInfo } = await auth.getEndUserInfo(uid);
    console.log("User profile", userInfo);
  } catch (error) {
    console.error("Failed to get end user info", error.message);
  }
};

Best practices:

  • Call getEndUserInfo from trusted backend code only; do not expose it directly to untrusted clients.
  • Log minimal necessary data for debugging; avoid logging full profiles in production.

Scenario 4: Get full profile for the current caller

Use this when you want the current caller’s full profile without manually passing uid:

import tcb from "@cloudbase/node-sdk";

const app = tcb.init({ env: "your-env-id" });
const auth = app.auth();

exports.main = async (event, context) => {
  try {
    const { userInfo } = await auth.getEndUserInfo();
    console.log("Current caller profile", userInfo);
  } catch (error) {
    console.error("Failed to get current caller profile", error.message);
  }
};

This relies on the environment providing the caller’s identity (e.g. within a CloudBase 云函数). If called where no caller context exists, refer to the official docs and handle errors gracefully.

Scenario 5: Query user by login identifier

Use this when you only know a user’s login identifier (phone, email, username, or custom ID) and need their CloudBase profile:

import tcb from "@cloudbase/node-sdk";

const app = tcb.init({ env: "your-env-id" });
const auth = app.auth();

exports.main = async (event, context) => {
  try {
    // Find by phone number
    const { userInfo: byPhone } = await auth.queryUserInfo({
      platform: "PHONE",
      platformId: "+86 13800000000",
    });

    // Find by email
    const { userInfo: byEmail } = await auth.queryUserInfo({
      platform: "EMAIL",
      platformId: "test@example.com",
    });

    // Find by customUserId
    const { userInfo: byCustomId } = await auth.queryUserInfo({
      platform: "CUSTOM",
      platformId: "your-customUserId",
    });

    console.log({ byPhone, byEmail, byCustomId });
  } catch (error) {
    console.error("Failed to query user info", error.message);
  }
};

Best practices:

  • Prefer uid when you already have it; use queryUserInfo only when needed.
  • Make sure platformId uses the exact format you used at sign‑up (e.g. +86 + phone number).

Scenario 6: Get client IP in a function

Use this for logging or basic IP‑based checks:

import tcb from "@cloudbase/node-sdk";

const app = tcb.init({ env: "your-env-id" });
const auth = app.auth();

exports.main = async (event, context) => {
  const ip = auth.getClientIP();
  console.log("Caller IP", ip);

  // e.g. block or flag suspicious IPs
};

Custom login tickets (Node side only)

Custom login lets you keep your existing user system while still mapping each user to a CloudBase account.

Scenario 7: Initialize Node SDK with custom login credentials

Before issuing tickets, install the custom login private key file from the CloudBase console and load it in Node:

import tcb from "@cloudbase/node-sdk";
import path from "node:path";

const app = tcb.init({
  env: "your-env-id",
  credentials: require(path.join(__dirname, "tcb_custom_login.json")),
});

const auth = app.auth();

Keep tcb_custom_login.json secret and never bundle it into frontend code.

Scenario 8: Issue a custom login ticket for a given customUserId

Use this in backend code that has already authenticated your own user and wants to let them log into CloudBase:

import tcb from "@cloudbase/node-sdk";

const app = tcb.init({
  env: "your-env-id",
  credentials: require("/secure/path/to/tcb_custom_login.json"),
});

const auth = app.auth();

exports.main = async (event, context) => {
  const customUserId = "your-customUserId";

  const ticket = auth.createTicket(customUserId, {
    refresh: 3600 * 1000,       // access_token refresh interval (ms)
    expire: 24 * 3600 * 1000,   // ticket expiration time (ms)
  });

  // Return the ticket to the trusted client (e.g. via HTTP response)
  return { ticket };
};

Constraints for customUserId (from official docs):

  • Length 4–32 characters.
  • Allowed characters: letters, digits, and _-#@(){}[]:.,<>+#~.

Best practices:

  • Only issue tickets after your own user authentication succeeds.
  • Store customUserId in your own user database and keep it stable over time.
  • Do not reuse customUserId for multiple distinct people.

Scenario 9: How this pairs with Web custom login

This skill only covers Node-side ticket issuance. For the client-side flow:

  • On the client (Web), use @cloudbase/js-sdk's custom login support:

- Call your backend endpoint that returns ticket. - Configure auth.setCustomSignFunc(async () => ticketFromBackend). - Call auth.signInWithCustomTicket() to finish login.

Keep the responsibility clear:

  • Node: authenticate your own user → create ticket → return ticket securely.
  • Web: receive ticket → sign into CloudBase using documented Web SDK APIs.

Node auth best practices

  • Single source of truth for identity

- Treat CloudBase uid as the primary key when relating end‑user records. - Use customUserId only as a bridge to your own user system.

  • Least privilege

- Perform authorization checks in Node using uid, roles, and ownership, not just login success. - Avoid exposing raw getEndUserInfo / queryUserInfo results directly to clients.

  • Error handling

- Wrap all auth.* calls in try/catch when they return promises. - Log error.message (and error.code if present), but avoid logging sensitive data.

  • Security

- Protect tcb_custom_login.json as you would any private key. - Rotate custom login keys according to CloudBase guidance when necessary. - Use HTTPS and proper authentication between your clients and Node backend when exchanging tickets.


Summary

Use this Node Auth skill whenever you need to:

  • Know who is calling your Node code in CloudBase.
  • Look up CloudBase users by uid or login identifier.
  • Bridge an existing user system into CloudBase with custom login tickets.
  • Apply consistent, secure, server‑side auth best practices.

For end‑to‑end experiences, pair this skill with:

  • Web‑side auth documentation (for all browser‑side login and UX using @cloudbase/js-sdk).
  • CloudBase HTTP auth documentation (for language‑agnostic HTTP integrations, if you are using those).

Treat the official CloudBase Auth Node SDK documentation as the canonical reference for Node auth APIs, and treat the scenarios in this file as vetted best‑practice building blocks.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

04

需要参考平台分布和安装热度时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Cursor

27.38%
按下载量换算1,535

Claude Code

21.26%
按下载量换算1,192

Codex

18.45%
按下载量换算1,035

trae

13.44%
按下载量换算754

OpenCode

7.17%
按下载量换算402

Gemini CLI

3.73%
按下载量换算209

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

来源信息

继续浏览同类 Skills