How to query for currently authenticated user with a token

44 views
Skip to first unread message

greenpea

unread,
Jan 29, 2015, 6:49:20 PM1/29/15
to orient-...@googlegroups.com
I'd like to use token based authentication to authenticate users from my node.js application, using the binary protocol via oriento. 

I realise this is fairly recent implementation so documented examples are lacking, but with a bit of digging around I was able to follow the test cases from jwt to get that part working: https://github.com/codemix/oriento/blob/master/test/core/jwt.js

With this I can authenticate a user and query the db with record level security for a user context. All great so far.

Now in my application I naturally need to identify the authenticated user. Given the token, is there a simple way to query for the authenticated user record? I'm considering using with a Bearer strategy in passport.js, see https://github.com/jaredhanson/passport-http-bearer. I'd like to do the equivalent with OrientDB as in the following example (looks like Mongo/mongoose).

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' });
    });
  }
));
Reply all
Reply to author
Forward
0 new messages