2014-10-06 105 views
0

尝试使用护照的WordPress https://www.npmjs.org/package/passport-wordpress的node.js,护照,WordPress的:所需要的“REDIRECT_URI”参数缺少

护照WordPress允许您使用您的凭据登录到node.js的应用创建一个演示在wordpress.com

我设立在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); 
    }); 
    } 

当我尝试授权,它进入这个网址(如一条线,我已经分成两这里阅读):

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

response_type=code&redirect_uri=&client_id= removed

我可以看到REDIRECT_URI中缺少的是URL,所以这并不奇怪,我得到这个错误:

Invalid request, please go back and try again.

Error Code: invalid_request

Error Message: The required "redirect_uri" parameter is missing.

不知道在哪里或如何在我的代码我应该提交REDIRECT_URI。

回答

1

您需要传递回调网址作为选项。

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); 
     }); 
    } 
)); 
+0

这工作!谢谢。一个小错字:秘密行后需要逗号: clientSecret:'shhh-its-a-secret', – user1147171 2014-10-07 02:50:46

相关问题