Skip to content

Instantly share code, notes, and snippets.

@tonypee
Created May 19, 2017 08:09
Show Gist options
  • Select an option

  • Save tonypee/e54a5581a883378c3b9ef65c698f46b8 to your computer and use it in GitHub Desktop.

Select an option

Save tonypee/e54a5581a883378c3b9ef65c698f46b8 to your computer and use it in GitHub Desktop.

Revisions

  1. tonypee created this gist May 19, 2017.
    37 changes: 37 additions & 0 deletions .js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    var express = require('express');
    var app = express();
    var passport = require('passport')
    , BearerStrategy = require('passport-http-bearer').Strategy;

    app.use(passport.initialize());

    passport.serializeUser(function(user, done) {
    done(null, user);
    });

    passport.deserializeUser(function(id, done) {
    done(null, id);
    });

    passport.use(new BearerStrategy(
    function(token, done) {
    console.log('check');
    done(null, 'you' + token)
    }
    ));

    app.post('/login',
    function(req, res) {
    console.log('OGIN FDFD');
    }
    );
    app.get('/test',
    passport.authenticate('bearer'),
    function(req, res) {
    console.log('OGIN FDFD');
    res.send('OK!' + req.user)
    }
    );
    app.listen(3000)

    console.log('STARTING SERVER...');