$npx -y skills add TencentCloudBase/cloudbase-skills --skill auth-wechatCloudBase WeChat Mini Program native authentication guide. This skill should be used when users need mini program identity handling, OPENID/UNIONID access, or wx.cloud auth behavior in projects where login is native and automatic.
| 1 | ## Standalone Install Note |
| 2 | |
| 3 | If this environment only installed the current skill, start from the CloudBase main entry and use the published `cloudbase/references/...` paths for sibling skills. |
| 4 | |
| 5 | - CloudBase main entry: `https://cnb.cool/tencent/cloud/cloudbase/cloudbase-skills/-/git/raw/main/skills/cloudbase/SKILL.md` |
| 6 | - Current skill raw source: `https://cnb.cool/tencent/cloud/cloudbase/cloudbase-skills/-/git/raw/main/skills/cloudbase/references/auth-wechat/SKILL.md` |
| 7 | |
| 8 | 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. |
| 9 | |
| 10 | ## Activation Contract |
| 11 | |
| 12 | ### Use this first when |
| 13 | |
| 14 | - The task is about WeChat Mini Program auth behavior, `wx.cloud` identity, `OPENID` / `UNIONID`, or how a mini program caller is identified in CloudBase. |
| 15 | - The project is a CloudBase mini program and the auth question is about native mini program identity rather than provider configuration. |
| 16 | |
| 17 | ### Read before writing code if |
| 18 | |
| 19 | - The request mentions mini program login, user identity in cloud functions, or `wx.cloud` auth assumptions. |
| 20 | - The user expects a Web-style login page or explicit token exchange in a mini program; route them back to native mini program auth behavior. |
| 21 | |
| 22 | ### Then also read |
| 23 | |
| 24 | - Mini program project implementation -> `../miniprogram-development/SKILL.md` (standalone fallback: `https://cnb.cool/tencent/cloud/cloudbase/cloudbase-skills/-/git/raw/main/skills/cloudbase/references/miniprogram-development/SKILL.md`) |
| 25 | - Cloud function implementation -> `../cloud-functions/SKILL.md` (standalone fallback: `https://cnb.cool/tencent/cloud/cloudbase/cloudbase-skills/-/git/raw/main/skills/cloudbase/references/cloud-functions/SKILL.md`) |
| 26 | |
| 27 | ### Do NOT use for |
| 28 | |
| 29 | - Web-based WeChat login or Web auth UI. |
| 30 | - Provider enable/disable or auth console setup. |
| 31 | - Generic Node-side auth flows outside mini program identity handling. |
| 32 | |
| 33 | ### Common mistakes / gotchas |
| 34 | |
| 35 | - Generating a Web-style login page for a `wx.cloud` mini program. |
| 36 | - Treating mini program auth as a provider-configuration problem. |
| 37 | - Forgetting that caller identity is injected in cloud functions automatically. |
| 38 | |
| 39 | ## When to use this skill |
| 40 | |
| 41 | Use this skill for **WeChat Mini Program (小程序) authentication** in a CloudBase project. |
| 42 | |
| 43 | Use it when you need to: |
| 44 | |
| 45 | - Implement identity-aware WeChat Mini Program flows with CloudBase |
| 46 | - Access user identity (openid, unionid) in cloud functions |
| 47 | - Understand how WeChat authentication integrates with CloudBase |
| 48 | - Build Mini Program features that require user identification |
| 49 | |
| 50 | **Key advantage:** WeChat Mini Program authentication with CloudBase is **seamless and automatic** - no complex OAuth flows needed. When a Mini Program calls a cloud function, the user's `openid` is automatically injected and verified by WeChat. |
| 51 | |
| 52 | **Do NOT use for:** |
| 53 | |
| 54 | - Web-based WeChat login (use the **auth-web** skill) |
| 55 | - Server-side auth with Node SDK (use the **auth-nodejs** skill) |
| 56 | - Non-WeChat authentication methods (use appropriate auth skills) |
| 57 | |
| 58 | --- |
| 59 | |
| 60 | ## How to use this skill (for a coding agent) |
| 61 | |
| 62 | 1. **Confirm CloudBase environment** |
| 63 | - Ask the user for: |
| 64 | - `env` – CloudBase environment ID |
| 65 | - Confirm the Mini Program is linked to the CloudBase environment |
| 66 | |
| 67 | 2. **Understand the authentication flow** |
| 68 | - WeChat Mini Program authentication is **native and automatic** |
| 69 | - No explicit login API calls needed in most cases |
| 70 | - User identity is automatically available in cloud functions |
| 71 | - CloudBase handles all authentication verification |
| 72 | |
| 73 | 3. **Pick a scenario from this file** |
| 74 | - For basic user identity in cloud functions, use **Scenario 2** |
| 75 | - For Mini Program initialization, use **Scenario 1** |
| 76 | - For calling a cloud function from the Mini Program and receiving user identity, use **Scenario 3** |
| 77 | - For testing authentication, use **Scenario 4** |
| 78 | |
| 79 | 4. **Follow CloudBase API shapes exactly** |
| 80 | - Use `wx-server-sdk` in cloud functions |
| 81 | - Use `wx.cloud` in Mini Program client code |
| 82 | - Treat method names and parameter shapes in this file as canonical |
| 83 | |
| 84 | 5. **If you're unsure about an API** |
| 85 | - Consult the official CloudBase Mini Program documentation |
| 86 | - Only use methods that appear in official documentation |
| 87 | |
| 88 | --- |
| 89 | |
| 90 | ## Core concepts |
| 91 | |
| 92 | ### How WeChat Mini Program authentication works with CloudBase |
| 93 | |
| 94 | 1. **Automatic authentication:** |
| 95 | - When a Mini Program user calls a cloud function, WeChat automatically injects the user's identity |
| 96 | - No need for complex OAuth flows or token management |
| 97 | - CloudBase verifies the authenticity of the identity |
| 98 | |
| 99 | 2. **User identifiers:** |
| 100 | - `OPENID` – Unique identif |