2016-04-27 31 views
-1

以下是我嘗試使用第三方提供程序進行身份驗證的代碼。我的身份驗證呼叫是在不同服務器上運行的服務api。如何在我的代碼使用服務API保證HTTP端點的安全

//app.js 
app.use(passport.initialize()); 
// Create our Express router 
var router = express.Router(); 
router.route('/test') 
    .get(**<first authenticate user using service api http://localhost:1000/authenticate>**, serviceController.getData); 
app.listen(2000); 

//authController.js 
var app = express(); 
var router = express.Router(); 
router.post("/authenticate",function(req,res){ 
//Using third party providers like LDAP or Facebook using Passport 
res.send("User authenticated");//Token will be send 
}); 
app.listen(1000); 

//authController.js - as function call it is working 
var passport = require('passport'); 
var BasicStrategy = require('passport-http').BasicStrategy; 

passport.use(new BasicStrategy(
    function (username, password, callback) { 
     // Success 
     //return callback(null, true); 
    } 
)); 

exports.isAuthenticated = passport.authenticate('basic', { session: false }); 

驗證用戶是否可以保證我的API http://localhost:2000/test使用LDAP或Facebook的身份驗證。我正在尋找類似於SSO的東西。

預期結果

當我打http://localhost:2000/test,請求必須向LDAP或http://localhost:1000/運行來驗證用戶併發送從「用戶認證」的響應Facebook服務器進行。 對此的任何幫助將非常有幫助。

回答

0

有幾個方法可以實現,使用Node.js的

護照提供了很多不同的登錄方式:twitter,google,facebook,linkedin,instagram。它們也很容易實現。

請在此檢查:http://passportjs.org/docs

+0

是的我意識到這一點。但是當我調用http:// localhost:2000/test時,我怎麼才能驗證用戶。示例我的ldap認證服務器運行在http:// localhost:1000/ldapauthentication – user4324324

+0

如果你想要一個代碼示例:http://stackoverflow.com/questions/13255389/ldapjs-authentification-user-login-setup –