$ npm i egg-google-auth --save
or
$ yarn add egg-google-auth
// {app_root}/config/plugin.js
exports.googleAuth = {
enable: true,
package: 'egg-google-auth',
};
// {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.
// 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')
Please open an issue here.