liangyali / passport-wechat

Passport strategy for authenticating with Wechat
158 stars 51 forks source link

Unknown authentication strategy "wechat" #29

Open zhaokunyao opened 7 months ago

zhaokunyao commented 7 months ago

http://localhost:8080/passport/login/wechat

Error: Unknown authentication strategy "wechat" at attempt (D:\kr_project\tmp\node_modules\passport\lib\middleware\authenticate.js:193:39) at authenticate (D:\kr_project\tmp\node_modules\passport\lib\middleware\authenticate.js:379:7) at Layer.handle [as handle_request] (D:\kr_project\tmp\node_modules\express\lib\router\layer.js:95:5) at next (D:\kr_project\tmp\node_modules\express\lib\router\route.js:137:13) at Route.dispatch (D:\kr_project\tmp\node_modules\express\lib\router\route.js:112:3) at Layer.handle [as handle_request] (D:\kr_project\tmp\node_modules\express\lib\router\layer.js:95:5) at D:\kr_project\tmp\node_modules\express\lib\router\index.js:281:22 at Function.process_params (D:\kr_project\tmp\node_modules\express\lib\router\index.js:335:12) at next (D:\kr_project\tmp\node_modules\express\lib\router\index.js:275:10) at Function.handle (D:\kr_project\tmp\node_modules\express\lib\router\index.js:174:3)

=======================

`/ login using wechat account / router.get('/login/wechat', passport.authenticate('wechat'));

/ wechat callback url / router.get('/oauth2/redirect/wechat', passport.authenticate('wechat', { failureRedirect: '/?error=wechat_login_failed', failureMessage: true }), function(req, res) { console.log('login wechat account success'); res.redirect('/employeeMode'); });

app.js

// configure wechat passport login var WechatStrategy = require('passport-wechat'); passport.use(new WechatStrategy({ appID: process.env['WECHAT_APP_ID'], name: 'WeChat', appSecret: process.env['WECHAT_APP_SECRET'], client: 'web', callbackURL: 'http://localhost:8080/passport/oauth2/redirect/wechat', scope: 'snsapi_base', state: '123' // getToken: {getToken}, // saveToken: {saveToken} }, function(accessToken, refreshToken, profile, done) { var provider = 'wechat'; return passportHelper.passport_call_back(provider, profile, done, db); } ));

`