An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# wxapp-auth

[![CircleCI](https://circleci.com/gh/cantonjs/wxapp-auth.svg?style=shield)](https://circleci.com/gh/cantonjs/wxapp-auth)
[![Build Status](https://travis-ci.org/cantonjs/wxapp-auth.svg?branch=master)](https://travis-ci.org/cantonjs/wxapp-auth)
[![Coverage Status](https://coveralls.io/repos/github/cantonjs/wxapp-auth/badge.svg?branch=master)](https://coveralls.io/github/cantonjs/wxapp-auth?branch=master)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com)
[![License](https://img.shields.io/badge/license-MIT_License-brightgreen.svg?style=flat)](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