liangyali / passport-wechat Goto Github PK
View Code? Open in Web Editor NEWPassport strategy for authenticating with Wechat
Passport strategy for authenticating with Wechat
When installing passport-wechat the following warning is produced:
npm WARN deprecated [email protected]: please use 'any-promise' instead
This is caused by [email protected] depending on [email protected]:
└─┬ [email protected]
├── [email protected]
├── [email protected]
└─┬ [email protected]
└─┬ [email protected]
├─┬ [email protected]
│ └── [email protected]
├── [email protected]
├─┬ [email protected]
│ └── [email protected]
├─┬ [email protected]
│ └── [email protected]
├── [email protected]
└── [email protected]
[email protected] and up depend on the advertised replacement module any-promise
getToken: {getToken},
saveToken: {saveToken}
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);
}
));
`
在 passport-wechat-public 中有提到说框架支持loopback-component-passport, 但是不知道该怎么用,可以给点提示吗?
这是我在providers里面的配置。
"wechat-login": {
"provider": "wechat",
"module": "passport-wechat",
"clientID": "wx0b1dd3ca76318a6b",
"clientSecret": "b79a000339b2fe3d26205a5355819a84",
"callbackURL": "/auth/wechat/callback",
"authPath": "/auth/wechat",
"callbackPath": "/auth/wechat/callback",
"successRedirect": "/auth/account",
"failureRedirect": "/login",
"scope": ["snsapi_base"],
"failureFlash": true
},
While I integrate feathers oauth2 with this passport-wechat
, and visit http://localhost:3035/auth/wechat I got error 'passport.initialize() middleware not in use'.
I check this error is from line 56 in passport-wechat
lib/strategy:
if (!req._passport) {
return this.error(new Error('passport.initialize() middleware not in use'));
}
and why req._passport is undefined?
versions
"@feathersjs/authentication": "^2.1.7",
"@feathersjs/authentication-jwt": "^2.0.0",
"@feathersjs/authentication-local": "^1.1.0",
"@feathersjs/authentication-oauth2": "^1.2.4"
"passport-wechat": "^2.0.4"
Finally I found If I comment the above line, it can still work correctly. So is that a false report error?
passport-wechat/lib/strategy.js
Line 145 in 48e3ea4
在 egg-passport 插件中,他传的是 ctx.req ,而不是 ctx,这行代码应该找到最兼容的方案。
我能够得到accessToken refreshToken 和 profile的值 使用 done(null , profile)总是 400 为什么呢
[Tue, 22 Dec 2015 06:34:53 GMT] "GET /api/user/auth/wechat" 302 2.512 ms 0
accessToken = OezXcEiiBSKSxW0eoylIePearzUkTO6p3rVb1p-rOuLbThz-b4NJ_F9rmlt9OTh8VdcY6WOSsawWxgD5F24Yx_ktwzsEcAyfCkIh_GEnw5Cw8GfLW9hPOC-NQ3sMkkVYlgAxSSg5LT5PsvsEnStDSw
refreshToken = OezXcEiiBSKSxW0eoylIePearzUkTO6p3rVb1p-rOuLbThz-b4NJ_F9rmlt9OTh8J4yZ2jOV_5NCO7iVscqOkxThtH7KUGPeduqnQMjDwS5ndJ7VmfD9B0Pv3wDSCSgqN-qZQSFlK8yDVUqEyEMQWQ
{ openid: 'on1lHxN-JI-eUE4F0Ha4p5x5p6ZE', unionid: undefined }
[Tue, 22 Dec 2015 06:37:08 GMT] "GET /api/user/auth/wechat/callback?code=011925dd48552cfcd02019b1df52528o&state=STATE" 400 170.527 ms 38
同时支持公众号登陆和网页登陆的时候会出现后一个覆盖前一个,建议给公众号登陆和网页登陆设置不一样的passport name
一直提示 Scope参数错误或没有Scope权限。
passport.use(new WechatStrategy({
appID: app.get('wechat').appId,
name: "wechat-login",
appSecret: app.get('wechat').secret,
client: "web",
callbackURL: "http://127.0.0.1:3000/auth/wechat/callback",
scope: "snsapi_base",
state: "login"
},
function (accessToken, refreshToken, profile, done) {
console.log(accessToken);
console.log(refreshToken);
console.log(profile);
done(err, profile)
}
));
app.get('/auth/wechat', passport.authenticate("wechat-login", {
state: "shit"
}));
app.get('/auth/wechat/callback', passport.authenticate('wechat-login', {
failureRedirect: "/login",
successReturnToOrRedirect: "/event/123"
}));
我发现虽然在 express 中打开了 app.use(passport.session())
,并且确认了 passport session 是工作的,但是每次session 工作成功之后,还是会在 passport-wechat 中被重定向到微信的认证页面。
是不是没有支持 passport session?
I need do dynamic Callback URL binding in Passport.Authenticate layer in my web app. The release version 2.0.2 in npm doesn't have your recent changes where callbackURL, state and scope could be overwritten. Could you consider releasing a new version with that feature?
Thanks!
I need to maintain the access token at the right time, in case of expired and refresh it. please expose this param to the callback, thx
回调函数是 5 个参数,npm 上是 4 个(少了个 expire_in),debug 了好久。。。
missing debug module.
在与其他项目整合时, 比如: https://github.com/feathersjs/authentication-oauth2
他们使用的是 clientID 和 clientSecret:
app.configure(oauth2({
name: 'facebook',
Strategy: FacebookStrategy,
clientID: '<your client id>',
clientSecret: '<your client secret>',
scope: ['public_profile', 'email']
}));
我们项目上用 appID, appSecret
这样命名上不一致在配置时可能出错, 是否可以考虑和他们统一?
The API property deprecated, Use require("wechat-oauth") instead
大哥麻烦跟进一下哦
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.