简体   繁体   English

使用服务 api 保护 HTTP 端点

[英]Securing HTTP endpoint using service api

Below is the code, where I am trying to authenticate using third party providers.下面是我尝试使用第三方提供商进行身份验证的代码。 My authentication call is a service api which is running in different servers.我的身份验证调用是一个在不同服务器上运行的服务 api。 How can authenticate users in my code如何在我的代码中验证用户

//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 });

Is it possible to secure my api http://localhost:2000/test using LDAP or Facebook authentication.是否可以使用 LDAP 或 Facebook 身份验证保护我的 api http://localhost:2000/test I am looking for something similar to SSO.我正在寻找类似于 SSO 的东西。

Expected result预期结果

When I hit http://localhost:2000/test , a request must be made to LDAP or facebook server running in http://localhost:1000/ to validate user and send the response from "User authenticated".当我点击http://localhost:2000/test 时,必须向在http://localhost:1000/ 中运行的 LDAP 或 Facebook 服务器发出请求以验证用户并发送来自“用户身份验证”的响应。 Any help on this will be really helpful.对此的任何帮助都将非常有帮助。

there are couple of possibilities to achieve that using node.js使用 node.js 有几种可能性可以实现

Passport provides plenty of different possibilities to login: twitter, google, facebook, linkedin, instagram. Passport 提供了多种不同的登录方式:twitter、google、facebook、linkedin、instagram。 They are pretty easy to implement as well.它们也很容易实现。

Check it here: http://passportjs.org/docs在这里检查: http : //passportjs.org/docs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM