How to use passport-local to authenticate in composer rest server

江枫思渺然 提交于 2019-12-28 14:59:05

问题


I want to use passport-local to authenticate user to login into composer rest server like other passport strategies ( e.g passport-github,passport-google).

So first I try to set COMPOSER_PROVIDER variable like this

"local": {
    "provider": "local",
    "module": "passport-local",
    "usernameField": "username",
    "passwordField": "password",
    "authPath": "/auth/local",
    "successRedirect": "/",
    "failureRedirect": "/"}

Then i run the server in docker (with mongo as persisted datasource) and add some user in database collection

The question is what's next step that i need to use this passport.Because i run this command and still get response with 401 Unauthorized

curl -H "Content-Type: application/json" -X POST -d '{"username":"{USER_NAME}","password":"{USER_PASSWORD}"}' http://localhost:3000/auth/local

Is it not enough to use this passport? Does i need to start another service to locally authenticate this login (e.g. GitHub oAuth Application )?


回答1:


It is possible to customize your composer-rest-server, based on the loopback framework, according to your requirements.

I suggest to read this tutorial from the official documentation.

https://hyperledger.github.io/composer/latest/integrating/customizing-the-rest-server




回答2:


I wanted to do that also initially, but then I just edit the server.js file on the composer rest server for basic auth at the end.

  1. check where your composer-rest-server is stored

npm root -g

  1. Open where server.js is located
cd /home/ubuntu/.nvm/versions/node/v8.10.0/lib/node_modules/composer-rest-server/server
  1. Add this to the code
const basicauth = require('basicauth-middleware');
app.use(basicauth('username', 'password!');


来源:https://stackoverflow.com/questions/46216970/how-to-use-passport-local-to-authenticate-in-composer-rest-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!