Auth Nodejs Cloudbase 标志

Auth Nodejs Cloudbase

组织热门
TencentCloudBase
auth-nodejs-cloudbase

CloudBase Node SDK 身份验证指南,介绍服务端身份识别、用户查询和自定义登录凭证。当 Node.js 代码需要读取调用者身份、查看终端用户,或将现有用户系统接入 CloudBase 时,请使用此技能;配置身份验证提供方或构建客户端登录界面时则不适用。

Add to TypingMind

概览

发布者TencentCloudBase
代码仓库CloudBase-AI-Toolkit
技能名称auth-nodejs-cloudbase
星标数
1.1K
复刻数
141
附带文件
仅含指令
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 指令自成一体

    模型所需的一切都包含在指令中,无需同步额外文件。

  • 开源

    由 TencentCloudBase 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Auth Nodejs Cloudbase AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/TencentCloudBase/CloudBase-AI-Toolkit/tree/main/config/source/skills/auth-nodejs-cloudbase
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/TencentCloudBase/CloudBase-AI-Toolkit.git /tmp/CloudBase-AI-Toolkit
mkdir -p .claude/skills
cp -r /tmp/CloudBase-AI-Toolkit/config/source/skills/auth-nodejs-cloudbase .claude/skills/auth-nodejs-cloudbase
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Auth Nodejs Cloudbase,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Auth Nodejs Cloudbase。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Auth Nodejs Cloudbase 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Sibling skills (local only)

Sibling CloudBase skills ship beside this skill. Use local relative paths such as ../auth-tool-cloudbase/SKILL.md.

If a referenced sibling skill file is missing from this environment, ask the user to install the full CloudBase plugin (or the missing skill). Do not HTTP-fetch remote skill or protocol markdown into the agent context.

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-cloudbase/SKILL.md
  • Web login UI that consumes custom tickets -> ../auth-web-cloudbase/SKILL.md
  • Raw HTTP auth client -> ../http-api-cloudbase/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?
  2. Confirm CloudBase environment and SDK

    • 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):
    ts
    import tcb from "@cloudbase/node-sdk";
    
    const app = tcb.init({ env: "your-env-id" });
    const auth = app.auth();
  3. 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.
  4. 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.
  5. 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 separates where users log in from where backend code runs:

  • Users log in through the supported auth methods (username/password, SMS, email, WeChat, custom login, anonymous — disabled by default, 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.
  2. 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.
  3. 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.
  4. 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:

ts
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:

ts
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:

ts
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:

ts
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:

ts
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:

ts
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:

ts
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:

ts
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.

常见问题

Auth Nodejs Cloudbase AI 技能有什么作用?

CloudBase Node SDK 身份验证指南,介绍服务端身份识别、用户查询和自定义登录凭证。当 Node.js 代码需要读取调用者身份、查看终端用户,或将现有用户系统接入 CloudBase 时,请使用此技能;配置身份验证提供方或构建客户端登录界面时则不适用。

为什么在 TypingMind 中使用 Auth Nodejs Cloudbase?

因为您只需安装一次,就能搭配任何模型使用。Auth Nodejs Cloudbase 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Auth Nodejs Cloudbase?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/TencentCloudBase/CloudBase-AI-Toolkit/tree/main/config/source/skills/auth-nodejs-cloudbase。TypingMind 会读取其中的 SKILL.md,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Auth Nodejs Cloudbase?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Auth Nodejs Cloudbase 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Auth Nodejs Cloudbase 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Auth Nodejs Cloudbase AI 技能免费吗?

是的。TencentCloudBase 已在 GitHub 上根据 MIT 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇