liangyali / passport-wechat

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

Scope 参数错误或没有Scope 权限 #12

Closed JoeShi closed 8 years ago

JoeShi commented 8 years ago

一直提示 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"
}));
oluul commented 8 years ago

好像搞明白了,微信开放平台和微信公众号是两个东西,你这里设置的client:web实际上是调用wechat-oauth库的getAuthorizeURLForWebsite方法,具体会调用 https://open.weixin.qq.com/connect/qrconnect。而这个地址就是开放平台的,不是公众号的,且scope必须为snsapi_login。公众号只提供snsapi_userinfo和snsapi_base

微信开发的确够头疼的。