auth-wechat-miniprogram

Resolve WeChat Mini Program user identity via cloud.getWXContext() in CloudBase.

Updated May 14, 2026
One-click install
npx skills add https://github.com/williamwang25/ams-admin --skill auth-wechat-miniprogram-williamwang25
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: auth-wechat-miniprogram
Source: https://github.com/williamwang25/ams-admin/tree/main/.windsurf/skills/cloudbase/references/auth-wechat
Command: npx skills add https://github.com/williamwang25/ams-admin --skill auth-wechat-miniprogram-williamwang25

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It resolves confusion about how to reliably identify WeChat Mini Program users when calling CloudBase cloud functions, including where OPENID/UNIONID come from and how to use them safely.

Core Features & Use Cases

  • Automatic identity injection: Use verified user identity in cloud functions without building a custom OAuth flow.
  • OPENID/APPID/UNIONID handling: Retrieve and interpret the correct identifiers returned by CloudBase for Mini Program callers.
  • Mini Program auth patterns: Initialize CloudBase in the Mini Program and confirm identity works end-to-end via a test cloud function.

Use case: You have a Mini Program feature that needs to query user-specific data when the client calls a cloud function; use OPENID to map requests to the correct user record.

Quick Start

Use this skill to implement Mini Program identity handling by calling cloud.getWXContext() inside your CloudBase cloud function to retrieve OPENID, APPID, and optional UNIONID.

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 WeChat Mini Program OPENID in a CloudBase cloud function?

To get WeChat Mini Program OPENID in a CloudBase cloud function, call cloud.getWXContext() using wx-server-sdk to retrieve automatically injected user identity containing OPENID, APPID, and UNIONID.

Do I need to build a custom OAuth flow to authenticate WeChat Mini Program users?

You do not need to build a custom OAuth flow for WeChat Mini Program authentication because CloudBase automatically injects verified user identity into cloud functions, allowing direct identity retrieval via cloud.getWXContext().

How does CloudBase inject UNIONID and APPID for Mini Program callers?

CloudBase injects UNIONID and APPID for Mini Program callers by securely passing these identifiers directly into the cloud function execution context, accessible through the object returned by cloud.getWXContext().

How do I initialize CloudBase in a WeChat Mini Program to test user identity?

Initialize CloudBase in WeChat Mini Program using wx.cloud, then deploy a simple test cloud function using wx-server-sdk and cloud.getWXContext() to confirm end-to-end that OPENID is successfully retrieved.

Why use cloud.DYNAMIC_CURRENT_ENV when accessing Mini Program identity in cloud functions?

Use cloud.DYNAMIC_CURRENT_ENV for environment selection in cloud functions to ensure wx-server-sdk dynamically targets the correct CloudBase environment when resolving Mini Program identity via cloud.getWXContext().

Can I use wx-server-sdk to map cloud function requests to specific Mini Program users?

You can use wx-server-sdk to map cloud function requests to specific Mini Program users by extracting the OPENID from cloud.getWXContext() and using it as a key to query user-specific data records.