https://github.com/cantonjs/claypot-wxapp-auth-plugin
Wechat mini program auth plugin for Claypot, built on top of wxapp-auth
https://github.com/cantonjs/claypot-wxapp-auth-plugin
Last synced: about 1 year ago
JSON representation
Wechat mini program auth plugin for Claypot, built on top of wxapp-auth
- Host: GitHub
- URL: https://github.com/cantonjs/claypot-wxapp-auth-plugin
- Owner: cantonjs
- License: mit
- Created: 2018-06-15T09:30:20.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-17T05:04:13.000Z (almost 8 years ago)
- Last Synced: 2024-10-12T09:25:40.873Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 82 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# claypot-wxapp-auth-plugin
[](https://travis-ci.org/cantonjs/claypot-wxapp-auth-plugin)
Wechat mini program auth plugin for [Claypot](https://github.com/cantonjs/claypot), built on top of [wxapp-auth](https://github.com/cantonjs/wxapp-auth).
## Installing
```bash
$ yarn add claypot claypot-restful-plugin claypot-wxapp-auth-plugin
```
## Usage and Example
**Claypotfile.js**
```js
module.exports = {
plugins: [
{
module: 'claypot-restful-plugin',
options: {},
},
{
module: 'claypot-wxapp-auth-plugin',
options: {
appId: '', // required
appSecret: '', // required
namespace: 'wxappAuth', // `ctx.clay.wxappAuth`
prefix: 'wxappAuth', // cache key prefix
ttl = 172800, // cache ttl (2 days by default)
security: 'wxapp', // `claypot-restful-plugin` security
signKey: 'id', // sign({ [signKey]: signValue })
},
},
],
};
```
**models/User.js**
```js
export default class Users {
async login({ body }, ctx) {
const { code } = body;
const { wxappAuth } = ctx.clay;
const { openid, sign } = await wxappAuth.login({ code });
const { accessToken, expiresIn } = await sign({ id: openid });
return { accessToken, expiresIn };
}
async getUserInfo({ body }, ctx) {
const { wxappAuth } = ctx.clay;
const userInfo = await wxappAuth.getUserInfo(body);
return userInfo;
}
// ...
}
```
## License
MIT