https://github.com/cantonjs/wxapp-auth
(Non-official) Wechat mini program (微信小程序) auth helper for Node.js
https://github.com/cantonjs/wxapp-auth
auth mini-program nodejs session user weapp wechat wechat-mini-program wei-xin wxapp
Last synced: 12 days ago
JSON representation
(Non-official) Wechat mini program (微信小程序) auth helper for Node.js
- Host: GitHub
- URL: https://github.com/cantonjs/wxapp-auth
- Owner: cantonjs
- License: mit
- Created: 2018-06-19T03:37:53.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-14T07:51:58.000Z (over 7 years ago)
- Last Synced: 2025-10-21T20:08:18.288Z (4 months ago)
- Topics: auth, mini-program, nodejs, session, user, weapp, wechat, wechat-mini-program, wei-xin, wxapp
- Language: JavaScript
- Homepage:
- Size: 70.3 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# wxapp-auth
[](https://circleci.com/gh/cantonjs/wxapp-auth)
[](https://travis-ci.org/cantonjs/wxapp-auth)
[](https://coveralls.io/github/cantonjs/wxapp-auth?branch=master)
[](http://makeapullrequest.com)
[](https://github.com/cantonjs/wxapp-auth/master/LICENSE.md)
(Non-official) Wechat mini program (a.k.a. 微信小程序) auth helper for Node.js.
## Table of Contents
- [Table of Contents](#table-of-contents)
- [Installation](#installation)
- [Usage](#usage)
- [Reference](#reference)
- [constructor(appId, appSecret)](#constructorappid-appsecret)
- [getUserInfo(params)](#getuserinfoparams)
- [getSession(params)](#getsessionparams)
- [License](#license)
## Installation
```bash
yarn add wxapp-auth
```
## Usage
```js
import WxappAuth from 'wxapp-auth';
(async function main() {
const wechatAuth = new WxappAuth('', '');
const userInfo = await wechatAuth.getUserInfo({
code: ''
rawData: '',
signature: '',
});
}());
```
## Reference
### constructor(appId, appSecret)
```js
new WxappAuth(appId, appSecret);
```
Create a `WxappAuth` instance.
#### Arguments
1. `appId` \: Wechat app id, required
2. `appSecret` \: Wechat app secret, required
### getUserInfo(params)
```js
wxappAuth.getUserInfo(params);
```
#### Arguments
1. Params \
- `code` \: `code` from wechat mini program `wx.login()`
- `sessionKey` \: Session key from [getSession(params)](#getsessionparams)
- `rawData` \: `rawData` from wechat mini program `wx.getUserInfo()`
- `signature` \: `signature` from wechat mini program `wx.getUserInfo()`
- `encryptedData` \: `encryptedData` from wechat mini program `wx.getUserInfo()`
- `iv` \: `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](https://developers.weixin.qq.com/miniprogram/dev/api/open.html#wxgetuserinfoobject) object
### getSession(params)
```js
wxappAuth.getSession(params);
```
#### Arguments
1. Params \
- `code` \: `code` from wechat mini program `wx.login()`, required
##### Returns
Promise of object containing `sessionKey`, `openid`, and optional `unionid`
## License
MIT