{"action":"created","issue":{"url":"https://api.github.com/repos/jaredhanson/passport/issues/524","repository_url":"https://api.github.com/repos/jaredhanson/passport","labels_url":"https://api.github.com/repos/jaredhanson/passport/issues/524/labels{/name}","comments_url":"https://api.github.com/repos/jaredhanson/passport/issues/524/comments","events_url":"https://api.github.com/repos/jaredhanson/passport/issues/524/events","html_url":"https://github.com/jaredhanson/passport/issues/524","id":188143010,"number":524,"title":"DOCS: Hello world example of OAuth with Connect, instead of Express","user":{"login":"keyscores","id":1364012,"avatar_url":"https://avatars.githubusercontent.com/u/1364012?v=3","gravatar_id":"","url":"https://api.github.com/users/keyscores","html_url":"https://github.com/keyscores","followers_url":"https://api.github.com/users/keyscores/followers","following_url":"https://api.github.com/users/keyscores/following{/other_user}","gists_url":"https://api.github.com/users/keyscores/gists{/gist_id}","starred_url":"https://api.github.com/users/keyscores/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keyscores/subscriptions","organizations_url":"https://api.github.com/users/keyscores/orgs","repos_url":"https://api.github.com/users/keyscores/repos","events_url":"https://api.github.com/users/keyscores/events{/privacy}","received_events_url":"https://api.github.com/users/keyscores/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-11-09T00:43:50Z","updated_at":"2016-11-20T18:17:05Z","closed_at":null,"body":"I'm struggling to find examples of passport using just Connectjs and Node HTTP.  Everything seems to reference express.\r\n\r\nIn the code below I  can get the first step of the OAuth to work (have github return a 'code'). But the next step gets stuck in a loop. Presumably because the passport 'validate callback' is not returning.\r\n\r\nbackground: I'm not planning on using express, I am however using connect middleware. I would like a simple hello world which does not involve sessions nor a database, but just the lowest level connect and node http server. \r\n\r\nThanks in advance.\r\n\r\n    var connect = require('connect');\r\n    var http = require('http');\r\n    var passport = require('passport');\r\n    var GithubStrategy = require('passport-github2').Strategy;\r\n    \r\n    var requestListener = connect();\r\n    \r\n    const credentials = {\r\n      serviceName: 'github',\r\n      registeredCallbackURL: 'http://localhost:3000/_oauth/github?close',\r\n      step1AuthorizeBasepath: 'https://github.com/login/oauth/authorize?',\r\n      step2RequestTokenBasepath: 'https://github.com/login/oauth/access_token?',\r\n      client: {\r\n        id: '<get-a-token>',\r\n        secret: '<get-a-token>',\r\n      },\r\n      defaultScope: ['user:email', 'admin:repo_hook'],\r\n      defaultXHRState: 'asdf1234', //or a username\r\n    };\r\n    \r\n    \r\n    \r\n    var USERID = { id: 1 , name: 'whatever'}\r\n    \r\n    \r\n    passport.use(new GithubStrategy({\r\n        clientID: credentials.client.id,\r\n        clientSecret: credentials.client.secret,\r\n        callbackURL: credentials.registeredCallbackURL,\r\n      },\r\n      //passport's verify callback\r\n      function(accessToken, refreshToken, profile, done) {\r\n        console.log('accessToken: ', accessToken);\r\n        console.log('refreshToken: ', refreshToken);\r\n        console.log('profile: ', profile);\r\n    \r\n        process.nextTick(function () {\r\n          return done(null, USERID);\r\n        });\r\n      }\r\n    ));\r\n    \r\n    // serialize the user\r\n    passport.serializeUser(function(user, done) {\r\n        return done(null, USERID.id);\r\n    });\r\n    \r\n    // used to deserialize the user\r\n    passport.deserializeUser(function(id, done) {\r\n        console.log('User', 'hello');\r\n        done( null,  USERID );\r\n    });\r\n    \r\n    requestListener.use('/login', passport.authenticate('github', { session: false }) );\r\n    \r\n    requestListener.use( '/_oauth/github',  passport.authenticate('github', {\r\n      session: false,\r\n      successRedirect: '/success',\r\n      failureRedirect: '/fail' })\r\n    );\r\n    \r\n    requestListener.use('success', function(req, res) {\r\n      console.log(req.url);\r\n      res.end('Login sucess\\n');\r\n    })\r\n    \r\n    \r\n    http.createServer( requestListener ).listen(3000);\r\n\r\n\r\n\r\nCross posted here:\r\n\r\nhttp://stackoverflow.com/questions/40498686/example-of-passport-js-oauth-without-using-express-only-using-connectjs-and-nod"},"comment":{"url":"https://api.github.com/repos/jaredhanson/passport/issues/comments/261794669","html_url":"https://github.com/jaredhanson/passport/issues/524#issuecomment-261794669","issue_url":"https://api.github.com/repos/jaredhanson/passport/issues/524","id":261794669,"user":{"login":"keyscores","id":1364012,"avatar_url":"https://avatars.githubusercontent.com/u/1364012?v=3","gravatar_id":"","url":"https://api.github.com/users/keyscores","html_url":"https://github.com/keyscores","followers_url":"https://api.github.com/users/keyscores/followers","following_url":"https://api.github.com/users/keyscores/following{/other_user}","gists_url":"https://api.github.com/users/keyscores/gists{/gist_id}","starred_url":"https://api.github.com/users/keyscores/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keyscores/subscriptions","organizations_url":"https://api.github.com/users/keyscores/orgs","repos_url":"https://api.github.com/users/keyscores/repos","events_url":"https://api.github.com/users/keyscores/events{/privacy}","received_events_url":"https://api.github.com/users/keyscores/received_events","type":"User","site_admin":false},"created_at":"2016-11-20T18:17:05Z","updated_at":"2016-11-20T18:17:05Z","body":"@jaredhanson ping"}}
{"actor":{"display_login":"keyscores"}}