egg-google-auth

基于Egg.js的谷歌身份验证器

Usage no npm install needed!

<script type="module">
  import eggGoogleAuth from 'https://cdn.skypack.dev/egg-google-auth';
</script>

README

egg-google-auth

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Install

$ npm i egg-google-auth --save
or
$ yarn add egg-google-auth

Usage

// {app_root}/config/plugin.js
exports.googleAuth = {
  enable: true,
  package: 'egg-google-auth',
};

Configuration

// {app_root}/config/config.default.js
exports.googleAuth = {
  appName: 'Application name',
  options: {
    // Time offset, used to avoid verification problems caused by user network delay. Default: 0
    timeExcursion: 0,
  },
};

see config/config.default.js for more detail.

Example

// Generate Google authentication private key
ctx.helper.generateGoogleSecretKey()

// Generate identity binding QR code information
ctx.helper.generateGoogleQrCodeText('your secretKey', 'your user')

// Get the base64 string of the QR code
ctx.helper.generateGoogleQrCodeUrl('your secretKey', 'your user')

// Get Google verification code
ctx.helper.generateGoogleCode('your secretKey')

// Get the Google verification code for the specified time slice
ctx.helper.generateGoogleCodeByTime('your secretKey', 'The first 30 seconds Date.now() / 1000 / 30')

// Google verification code verification
ctx.helper.googleAuthVerify('your secretKey', 'TOTP verification code entered by the user')

WeChat applet version of the client

weapp-google-auth

Questions & Suggestions

Please open an issue here.

License

MIT