# passport-miniapp

> 小程序登陆验证

Latest version **1.0.4** (published 2020-03-20) · ISC license · 0 weekly downloads

## Install

```sh
npm install passport-miniapp
pnpm add passport-miniapp
yarn add passport-miniapp
bun add passport-miniapp
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2020-03-20 |
| First published | 2020-02-25 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 5.2 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | yujintang |

## Links

- npm: https://www.npmjs.com/package/passport-miniapp
- Repository: https://github.com/yujintang/passport-miniapp
- Homepage: https://github.com/yujintang/passport-miniapp#readme
- Issues: https://github.com/yujintang/passport-miniapp/issues
- npm.io page: https://npm.io/package/passport-miniapp

## Dependencies (2)

- [passport](https://npm.io/package/passport.md) ^0.4.1
- [iconv-lite](https://npm.io/package/iconv-lite.md) ^0.5.1

## Recent versions

- 1.0.4 (latest) — 2020-03-20
- 1.0.3 — 2020-03-19
- 1.0.2 — 2020-03-19
- 1.0.1 — 2020-02-25
- 1.0.0 — 2020-02-25

## README

# passport-miniapp
小程序登陆验证


## Install
```shell
npm install passport-miniapp
```
## Usage

### In Nestjs
```js
import { Strategy } from 'passport-miniapp';
import { PassportStrategy } from '@nestjs/passport';
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';

@Injectable()
export class MiniAppStrategy extends PassportStrategy(Strategy) {
  constructor(
    private readonly configService: ConfigService,
  ) {
  super({
    appid: configService.get('appid'),
    secret: configService.get('secret'),
    codeField: 'code',
    passReqToCallback: true,
  });
  }

  async validate(req, retbody): Promise<any> {
    if (retbody.errcode) {
      throw new UnauthorizedException(retbody.errmsg);
    }
    return {
      session_key: retbody.session_key,
      openid: retbody.openid,
      unionid: retbody.unionid,
    };
  }
}

```

---
_Source: https://npm.io/package/passport-miniapp · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
