wechat-mini-program-auth

0.1.1 • Public • Published

wechat-mini-program-auth

CircleCI Build Status Coverage Status PRs Welcome License

(Non-official) Wechat mini program auth helper for Node.js.

Table of Contents

Installation

yarn add wechat-mini-program-auth

Usage

import WechatMiniProgramAuth from 'wechat-mini-program-auth';
 
(async function main() {
  const wechatAuth = new WechatMiniProgramAuth({
    appId: '<WECHAT_APP_ID>',
    appSecret: '<WECHAT_APP_SECRET>',
  }));
 
  const userInfo = await wechatAuth.getUserInfo({
    code: '<LOGIN_CODE>'
    rawData: '<RAW_DATA>',
    signature: '<SIGNATURE>',
  });
}());

Reference

constructor(appId, appSecret)

new WechatMiniProgramAuth(appId, appSecret)

Create a WechatMiniProgramAuth instance.

Arguments

  1. appId <String>: Wechat app id, required
  2. appSecret <String>: Wechat app secret, required

getUserInfo(params)

wechatMiniProgramAuth.getUserInfo(params)

Arguments

  1. Params <Object>
  • code <String>: code from wechat mini program wx.login()
  • sessionKey <String>: Session key from getSession(params)
  • rawData <String>: rawData from wechat mini program wx.getUserInfo()
  • signature <String>: signature from wechat mini program wx.getUserInfo()
  • encryptedData <String>: encryptedData from wechat mini program wx.getUserInfo()
  • iv <String>: iv from wechat mini program wx.getUserInfo()
Note
  • One of code or sessionKey is required
  • One of rawData and signature, or encryptedData and iv are required

Returns

Promise of UserInfo object

getSession(params)

wechatMiniProgramAuth.getSession(params)

Arguments

  1. Params <Object>
  • code <String>: code from wechat mini program wx.login(), required
Returns

Promise of object containing sessionKey, openid, and optional unionid

License

MIT

Dependents (1)

Package Sidebar

Install

npm i wechat-mini-program-auth

Weekly Downloads

1

Version

0.1.1

License

MIT

Unpacked Size

23.1 kB

Total Files

17

Last publish

Collaborators

  • cap32