{"action":"created","issue":{"url":"https://api.github.com/repos/jaredhanson/passport-facebook/issues/123","repository_url":"https://api.github.com/repos/jaredhanson/passport-facebook","labels_url":"https://api.github.com/repos/jaredhanson/passport-facebook/issues/123/labels{/name}","comments_url":"https://api.github.com/repos/jaredhanson/passport-facebook/issues/123/comments","events_url":"https://api.github.com/repos/jaredhanson/passport-facebook/issues/123/events","html_url":"https://github.com/jaredhanson/passport-facebook/issues/123","id":92483639,"number":123,"title":"Extend the the user creation and login process","user":{"login":"mikesparr","id":5553105,"avatar_url":"https://avatars.githubusercontent.com/u/5553105?v=3","gravatar_id":"","url":"https://api.github.com/users/mikesparr","html_url":"https://github.com/mikesparr","followers_url":"https://api.github.com/users/mikesparr/followers","following_url":"https://api.github.com/users/mikesparr/following{/other_user}","gists_url":"https://api.github.com/users/mikesparr/gists{/gist_id}","starred_url":"https://api.github.com/users/mikesparr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikesparr/subscriptions","organizations_url":"https://api.github.com/users/mikesparr/orgs","repos_url":"https://api.github.com/users/mikesparr/repos","events_url":"https://api.github.com/users/mikesparr/events{/privacy}","received_events_url":"https://api.github.com/users/mikesparr/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-07-01T20:59:49Z","updated_at":"2016-02-04T04:23:19Z","closed_at":"2016-02-04T02:31:18Z","body":"## Issue 1: remoteHook event on User.create fails after adding Passport\r\nWhen adding passport does it override the built-in User model for Loopback and somehow block events from registering for remote hooks?\r\n\r\n## Issue 2: Passport login does not create Loopback accessToken\r\nIs there a way to extend the passport login for all strategies to add logic to also call Loopback's `User.login()`.  Their function returns the `accessToken` which would be used for subsequent requests and leverage their ACL and RBAC.\r\n\r\n----\r\n\r\nTesting out Loopback and https://github.com/strongloop/loopback-example-passport and they have concept of \"remote hooks\" and \"operation hooks\".  In their system when a `User` is created, you can attach a hook to the `create` and add custom logic like emailing a verification link.\r\n\r\nAfter integrating Passport into Loopback in their example application, and using a local strategy for passport, it appears the `create` is not recognized as remote hook event so I cannot extend that with a remote hook like the following.\r\n\r\n`user.js` (model config)\r\n~~~\r\nvar path = require('path');\r\nvar app = require(path.resolve(__dirname, '../../server/server'));\r\n\r\nmodule.exports = function(user) {\r\n  //send verification email after registration\r\n  user.afterRemote('create', function(context, user, next) {\r\n    console.log('> user.afterRemote triggered');\r\n\r\n    var options = {\r\n      type: 'email',\r\n      to: user.email,\r\n      from: 'noreply@myco.com',\r\n      subject: 'Thanks for registering.',\r\n      template: path.resolve(__dirname, '../../server/views/pages/verify.jade'),\r\n      redirect: 'pages/verified',\r\n      user: user\r\n    };\r\n\r\n    user.verify(options, function(err, response) {\r\n      if (err) {\r\n        next(err);\r\n        return;\r\n      }\r\n\r\n      console.log('> verification email sent:', response);\r\n\r\n      context.res.render('pages/response', {\r\n        title: 'Signed up successfully',\r\n        content: 'Please check your email and click on the verification link '\r\n          + 'before logging in.',\r\n        redirectTo: '/',\r\n        redirectToLinkText: 'Log in'\r\n      });\r\n    });\r\n  });\r\n\r\n  //send password reset link when requested\r\n  user.on('resetPasswordRequest', function(info) {\r\n    var url = 'http://' + app.get('email_link_domain') + '/reset-password';\r\n    var html = 'Click <a href=\"' + url + '?access_token=' + info.accessToken.id\r\n      + '\">here</a> to reset your password';\r\n\r\n    user.app.models.Email.send({\r\n      to: info.email,\r\n      from: info.email,\r\n      subject: 'Password reset',\r\n      html: html\r\n    }, function(err) {\r\n      if (err) return console.log('> error sending password reset email');\r\n      console.log('> sending password reset email to:', info.email);\r\n    });\r\n  });\r\n};\r\n~~~\r\n\r\n`routes.js` (custom routes)\r\n~~~\r\n    router.post('/signup', function (req, res, next) {\r\n\r\n      var newUser = {};\r\n      newUser.email = req.body.email.toLowerCase();\r\n      newUser.username = req.body.username.trim();\r\n      newUser.password = req.body.password;\r\n\r\n      User.create(newUser, function (err, user) {\r\n        if (err) {\r\n          req.flash('error', err.message);\r\n          return res.redirect('back');\r\n        } else {\r\n          // Passport exposes a login() function on req (also aliased as logIn())\r\n          // that can be used to establish a login session. This function is\r\n          // primarily used when users sign up, during which req.login() can\r\n          // be invoked to log in the newly registered user.\r\n          req.login(user, function (err) {\r\n            if (err) {\r\n              req.flash('error', err.message);\r\n              return res.redirect('back');\r\n            }\r\n            console.log('Logged user in using Passport req.login()');\r\n            console.log(req.user);\r\n            return res.redirect('/auth/account');\r\n          });\r\n        }\r\n      });\r\n    });\r\n~~~\r\n\r\nIt's unclear why the `create` is not registering the remote hook.  In other tests without Passport integration, it works, so I'm guessing something happens once Passport added to the User model in Loopback.  \r\n\r\nI appreciate any insights or ideas why this might be occurring or if you've heard adding Passport to Loopback whether it eliminates some events from being recognized."},"comment":{"url":"https://api.github.com/repos/jaredhanson/passport-facebook/issues/comments/179621886","html_url":"https://github.com/jaredhanson/passport-facebook/issues/123#issuecomment-179621886","issue_url":"https://api.github.com/repos/jaredhanson/passport-facebook/issues/123","id":179621886,"user":{"login":"mikesparr","id":5553105,"avatar_url":"https://avatars.githubusercontent.com/u/5553105?v=3","gravatar_id":"","url":"https://api.github.com/users/mikesparr","html_url":"https://github.com/mikesparr","followers_url":"https://api.github.com/users/mikesparr/followers","following_url":"https://api.github.com/users/mikesparr/following{/other_user}","gists_url":"https://api.github.com/users/mikesparr/gists{/gist_id}","starred_url":"https://api.github.com/users/mikesparr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikesparr/subscriptions","organizations_url":"https://api.github.com/users/mikesparr/orgs","repos_url":"https://api.github.com/users/mikesparr/repos","events_url":"https://api.github.com/users/mikesparr/events{/privacy}","received_events_url":"https://api.github.com/users/mikesparr/received_events","type":"User","site_admin":false},"created_at":"2016-02-04T04:23:19Z","updated_at":"2016-02-04T04:23:19Z","body":"https://github.com/strongloop/loopback Try here"}}