{"action":"created","issue":{"url":"https://api.github.com/repos/jaredhanson/passport-google/issues/6","repository_url":"https://api.github.com/repos/jaredhanson/passport-google","labels_url":"https://api.github.com/repos/jaredhanson/passport-google/issues/6/labels{/name}","comments_url":"https://api.github.com/repos/jaredhanson/passport-google/issues/6/comments","events_url":"https://api.github.com/repos/jaredhanson/passport-google/issues/6/events","html_url":"https://github.com/jaredhanson/passport-google/issues/6","id":10316130,"number":6,"title":"Windows Azure /auth/google/return","user":{"login":"ajonp","id":3102249,"avatar_url":"https://avatars.githubusercontent.com/u/3102249?v=3","gravatar_id":"","url":"https://api.github.com/users/ajonp","html_url":"https://github.com/ajonp","followers_url":"https://api.github.com/users/ajonp/followers","following_url":"https://api.github.com/users/ajonp/following{/other_user}","gists_url":"https://api.github.com/users/ajonp/gists{/gist_id}","starred_url":"https://api.github.com/users/ajonp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ajonp/subscriptions","organizations_url":"https://api.github.com/users/ajonp/orgs","repos_url":"https://api.github.com/users/ajonp/repos","events_url":"https://api.github.com/users/ajonp/events{/privacy}","received_events_url":"https://api.github.com/users/ajonp/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2013-01-25T16:07:27Z","updated_at":"2016-05-13T13:27:54Z","closed_at":"2013-02-21T23:48:13Z","body":"On localhost this works, but not on Windows Azure.\r\n\r\nvar express = require('express')\r\n  , engine = require('ejs-locals')\r\n  , passport = require('passport')\r\n  , util = require('util')\r\n  , GoogleStrategy = require('passport-google').Strategy;\r\n\r\n\r\n// Passport session setup.\r\n//   To support persistent login sessions, Passport needs to be able to\r\n//   serialize users into and deserialize users out of the session.  Typically,\r\n//   this will be as simple as storing the user ID when serializing, and finding\r\n//   the user by ID when deserializing.  However, since this example does not\r\n//   have a database of user records, the complete Google profile is serialized\r\n//   and deserialized.\r\npassport.serializeUser(function(user, done) {\r\n  done(null, user);\r\n});\r\n\r\npassport.deserializeUser(function(obj, done) {\r\n  done(null, obj);\r\n});\r\n\r\n\r\n// Use the GoogleStrategy within Passport.\r\n//   Strategies in passport require a `validate` function, which accept\r\n//   credentials (in this case, an OpenID identifier and profile), and invoke a\r\n//   callback with a user object.\r\npassport.use(new GoogleStrategy({\r\n    returnURL: 'http://nodejs-test.azurewebsites.net/auth/google/return',\r\n    realm: 'http://nodejs-test.azurewebsites.net/'\r\n\t// returnURL: 'http://localhost:1337/auth/google/return',\r\n    // realm: 'http://localhost:1337/'\r\n  },\r\n  function(identifier, profile, done) {\r\n    // asynchronous verification, for effect...\r\n    process.nextTick(function () {\r\n      \r\n      // To keep the example simple, the user's Google profile is returned to\r\n      // represent the logged-in user.  In a typical application, you would want\r\n      // to associate the Google account with a user record in your database,\r\n      // and return that user instead.\r\n      profile.identifier = identifier;\r\n      return done(null, profile);\r\n    });\r\n  }\r\n));\r\n\r\nvar app = express();\r\n// use ejs-locals\r\napp.engine('ejs', engine);\r\n// configure Express\r\napp.configure(function() {\r\n  app.set('views', __dirname + '/views');\r\n  app.set('view engine', 'ejs');\r\n  app.set('port', process.env.PORT || 1337);\r\n  app.use(express.logger());\r\n  app.use(express.cookieParser());\r\n  app.use(express.bodyParser());\r\n  app.use(express.methodOverride());\r\n  app.use(express.session({ secret: 'keyboard cat' }));\r\n  // Initialize Passport!  Also use passport.session() middleware, to support\r\n  // persistent login sessions (recommended).\r\n  app.use(passport.initialize());\r\n  app.use(passport.session());\r\n  app.use(app.router);\r\n  app.use(express.static(__dirname + '/../../public'));\r\n});\r\n\r\n\r\napp.get('/', function(req, res){\r\n  res.render('index', { user: req.user, title: 'AJONP - Login'});\r\n});\r\n\r\napp.get('/account', ensureAuthenticated, function(req, res){\r\n  res.render('account', { user: req.user });\r\n});\r\n\r\napp.get('/login', function(req, res){\r\n  res.render('login', { user: req.user });\r\n});\r\n\r\n// GET /auth/google\r\n//   Use passport.authenticate() as route middleware to authenticate the\r\n//   request.  The first step in Google authentication will involve redirecting\r\n//   the user to google.com.  After authenticating, Google will redirect the\r\n//   user back to this application at /auth/google/return\r\napp.get('/auth/google', \r\n  passport.authenticate('google', { failureRedirect: '/login' }),\r\n  function(req, res) {\r\n    res.redirect('/');\r\n  });\r\n\r\n// GET /auth/google/return\r\n//   Use passport.authenticate() as route middleware to authenticate the\r\n//   request.  If authentication fails, the user will be redirected back to the\r\n//   login page.  Otherwise, the primary route function function will be called,\r\n//   which, in this example, will redirect the user to the home page.\r\napp.get('/auth/google/return', \r\n  passport.authenticate('google', { failureRedirect: '/login' }),\r\n  function(req, res) {\r\n    res.redirect('/');\r\n  });\r\n\r\napp.get('/logout', function(req, res){\r\n  req.logout();\r\n  res.redirect('/');\r\n});\r\n\r\n\r\n// Simple route middleware to ensure user is authenticated.\r\n//   Use this route middleware on any resource that needs to be protected.  If\r\n//   the request is authenticated (typically via a persistent login session),\r\n//   the request will proceed.  Otherwise, the user will be redirected to the\r\n//   login page.\r\nfunction ensureAuthenticated(req, res, next) {\r\n  if (req.isAuthenticated()) { return next(); }\r\n  res.redirect('/login')\r\n}\r\n"},"comment":{"url":"https://api.github.com/repos/jaredhanson/passport-google/issues/comments/219042477","html_url":"https://github.com/jaredhanson/passport-google/issues/6#issuecomment-219042477","issue_url":"https://api.github.com/repos/jaredhanson/passport-google/issues/6","id":219042477,"user":{"login":"danny8002","id":7395403,"avatar_url":"https://avatars.githubusercontent.com/u/7395403?v=3","gravatar_id":"","url":"https://api.github.com/users/danny8002","html_url":"https://github.com/danny8002","followers_url":"https://api.github.com/users/danny8002/followers","following_url":"https://api.github.com/users/danny8002/following{/other_user}","gists_url":"https://api.github.com/users/danny8002/gists{/gist_id}","starred_url":"https://api.github.com/users/danny8002/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danny8002/subscriptions","organizations_url":"https://api.github.com/users/danny8002/orgs","repos_url":"https://api.github.com/users/danny8002/repos","events_url":"https://api.github.com/users/danny8002/events{/privacy}","received_events_url":"https://api.github.com/users/danny8002/received_events","type":"User","site_admin":false},"created_at":"2016-05-13T13:27:54Z","updated_at":"2016-05-13T13:27:54Z","body":"https://github.com/jaredhanson/passport-google/issues/6"}}