auth-wechat-miniprogram

Configure WeChat Mini Program CloudBase authentication using wx.cloud.init and cloud.getWXContext().

2|1|Updated Apr 3, 2026
One-click install
npx skills add https://github.com/lxb031018/qintu --skill auth-wechat-miniprogram-lxb031018
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: auth-wechat-miniprogram
Source: https://github.com/lxb031018/qintu/tree/main/.codebuddy/skills/auth-wechat
Command: npx skills add https://github.com/lxb031018/qintu --skill auth-wechat-miniprogram-lxb031018

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It solves the challenge of correctly handling WeChat Mini Program authentication in a CloudBase project so you can reliably identify the signed-in user without building complex OAuth login flows.

Core Features & Use Cases

  • Automatic identity injection: retrieves verified OPENID, APPID, and optionally UNIONID when a mini program calls a cloud function.
  • Cloud function identity access: uses wx-server-sdk with cloud.getWXContext() to implement user-specific logic securely.
  • Mini program initialization: initializes CloudBase early in the mini program lifecycle via wx.cloud.init() to ensure auth behavior works as expected.

Use case example: a mini program calls a CloudBase cloud function to fetch user-specific navigation routes; the function uses OPENID from cloud.getWXContext() to query and return only that user's data.

Quick Start

Use this skill to implement mini program identity handling by initializing CloudBase in app.js and reading the caller identity in the target cloud function with cloud.getWXContext().

Frequently Asked Questions about auth-wechat-miniprogram

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I get OPENID in a WeChat mini program cloud function?

To get OPENID in a WeChat mini program cloud function, initialize wx.cloud.init in the app and call cloud.getWXContext() within the function to retrieve the verified caller identity.

What is the best way to authenticate WeChat mini program users with CloudBase?

The best way to authenticate WeChat mini program users with CloudBase is using wx-server-sdk and cloud.getWXContext() to automatically inject secure identity context without building complex OAuth flows.

Do I need provider-configuration for WeChat mini program identity context?

No, you do not need provider-configuration for WeChat mini program identity context. You must avoid provider-configuration and web-login flows, relying instead on wx.cloud initialization.

How do I initialize CloudBase in a WeChat mini program?

To initialize CloudBase in a WeChat mini program, call wx.cloud.init() early in the app lifecycle, such as in app.js, to ensure cloud functions can correctly access user authentication behavior.

Why does cloud.getWXContext() require cloud.DYNAMIC_CURRENT_ENV?

Using cloud.getWXContext() with cloud.DYNAMIC_CURRENT_ENV ensures the wx-server-sdk targets the current runtime environment, securely returning OPENID, APPID, and UNIONID for user-specific logic.

Can I use web-login flows to get UNIONID in WeChat mini programs?

No, you cannot use web-login flows to get UNIONID in WeChat mini programs. You must avoid web-login flows and instead use cloud.getWXContext() to optionally retrieve UNIONID securely.