【问题标题】:node.js, passport-wordpress: The required "redirect_uri" parameter is missingnode.js,passport-wordpress:缺少所需的“redirect_uri”参数
【发布时间】:2014-11-30 09:18:51
【问题描述】:

尝试使用 passport-wordpress 创建演示 https://www.npmjs.org/package/passport-wordpress

passport-wordpress 允许您使用您在 wordpress.com 上的凭据登录到 node.js 应用程序

我在 developer.wordpress.com/apps 上设置了我的 Wordpress 应用程序:

OAuth Information
Client ID <removed>
Client Secret <removed>
Redirect URL  http://greendept.com/wp-pass/
Javascript Origins    http://wp-node2.herokuapp.com
Type  Web
Request token URL https://public-api.wordpress.com/oauth2/token
Authorize URL https://public-api.wordpress.com/oauth2/authorize
Authenticate URL  https://public-api.wordpress.com/oauth2/authenticate

在我的 node.js 应用中:

    var CLIENT_ID = <removed>;
    var CLIENT_SECRET = <removed>;
    passport.use(new WordpressStrategy({
    clientID: CLIENT_ID,
    clientSecret: CLIENT_SECRET
  },
  function(accessToken, refreshToken, profile, done) {
    User.findOrCreate({ WordpressId: profile.id }, function (err, user) {
      return done(err, user);
    });
  }

当我尝试授权时,它会转到这个 URL(一行,为了便于阅读,我在这里分为两行):

https://public-api.wordpress.com/oauth2/authorize?

response_type=code&redirect_uri=&client_id= 已移除

我可以看到该 URL 中缺少 redirect_uri,因此收到此错误并不奇怪:

请求无效,请返回重试。

错误代码:invalid_request

错误消息:缺少所需的“redirect_uri”参数。

不确定我应该在代码中的何处或如何提交 redirect_uri。

【问题讨论】:

    标签: wordpress node.js express oauth-2.0 passport.js


    【解决方案1】:

    您需要传递一个回调 url 作为选项。

    来自passport-wordpress

    The strategy requires a verify callback, which accepts these credentials and 
    calls done providing a user, as well as options specifying a client ID, 
    client secret, and callback URL.
    

    来自lib/strategy.js

    Examples:
    
      passport.use(new WordpressStrategy({
          clientID: '123-456-789',
          clientSecret: 'shhh-its-a-secret',
          callbackURL: 'https://www.example.net/auth/wordpress/callback'
        },
        function(accessToken, refreshToken, profile, done) {
          User.findOrCreate(..., function (err, user) {
            done(err, user);
          });
        }
      ));
    

    【讨论】:

    • 成功了!谢谢你。一个小错字:您需要在密码行后面加一个逗号:clientSecret: 'shhh-its-a-secret',
    猜你喜欢
    • 2015-12-31
    • 2016-04-14
    • 2013-01-10
    • 1970-01-01
    • 2017-02-27
    • 2021-09-02
    • 1970-01-01
    • 1970-01-01
    • 2020-04-24
    相关资源
    最近更新 更多