2014-10-06 80 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

相關問題