简体   繁体   中英

How can i authenticate the nodejs application using ionic framework?

I am trying to create a web service for my phone gap application.

Backend is written in nodejs. They have used Passport , local_login method for the same. which is giving me access_token as well.

I am able to login and able to fetch access token using phone gap application.

How can i fetch other data, which is required session authentication using Phone gap

any idea ?

You can use passport-http-bearer

passport.use(new BearerStrategy(
  function(token, done) {
    User.findOne({ token: token }, function (err, user) {
      if (err) { return done(err); }
      if (!user) { return done(null, false); }
      return done(null, user, { scope: 'all' });
    });
  }
));


Authenticate Requests


app.get('/profile', 
  passport.authenticate('bearer', { session: false }),
  function(req, res) {
    res.json(req.user);
  });

for more details visit this link https://github.com/jaredhanson/passport-http-bearer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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