{"id":16731596,"url":"https://github.com/missinglink/passport-facebook-canvas","last_synced_at":"2025-04-10T11:20:33.599Z","repository":{"id":12207079,"uuid":"14813080","full_name":"missinglink/passport-facebook-canvas","owner":"missinglink","description":"Facebook Canvas authentication strategy for Passport and Node.js.","archived":false,"fork":false,"pushed_at":"2015-04-18T09:50:32.000Z","size":181,"stargazers_count":15,"open_issues_count":2,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-20T11:12:30.620Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/missinglink.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-11-30T01:03:40.000Z","updated_at":"2021-09-16T16:18:29.000Z","dependencies_parsed_at":"2022-09-07T04:52:43.073Z","dependency_job_id":null,"html_url":"https://github.com/missinglink/passport-facebook-canvas","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/missinglink%2Fpassport-facebook-canvas","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/missinglink%2Fpassport-facebook-canvas/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/missinglink%2Fpassport-facebook-canvas/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/missinglink%2Fpassport-facebook-canvas/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/missinglink","download_url":"https://codeload.github.com/missinglink/passport-facebook-canvas/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248208602,"owners_count":21065203,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-12T23:38:03.514Z","updated_at":"2025-04-10T11:20:33.580Z","avatar_url":"https://github.com/missinglink.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Passport Strategy for Facebook Canvas apps\n---\n\nUse this strategy to log users in to your Facebook Canvas app automatically.\n\n**Note:** This strategy simply augments [passport-facebook](https://github.com/jaredhanson/passport-facebook), if you don't need Facebook Canvas support you should use that module instead.\n\n```bash\nnpm install passport-facebook-canvas --save\n```\n\n[![NPM](https://nodei.co/npm/passport-facebook-canvas.png?downloads=true\u0026stars=true)](https://nodei.co/npm/passport-facebook-canvas/)\n\n### App Settings\n\n![Facebook Settings](https://s3.amazonaws.com/peter.johnson/embed-images/passport-facebook-canvas-readme1.png)\n\n### Configuring Secure Canvas Url\n\nFacebook has deprecated `Canvas Url` in favour of `Secure Canvas Url` and so requires setting up an SSL cert. You can produce a `self-signed certificate` with a command such as this: (don't set a password for a testing cert)\n```bash\n# Ubuntu\nsudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout self_signed_ssl.key -out self_signed_ssl.crt\n```\n\nThen you must tell `express` to listen on another port, something like this:\n```javascript\nvar certificate = {\n  key: fs.readFileSync(path.resolve(__dirname, './self_signed_ssl.key'), 'utf8'),\n  cert: fs.readFileSync(path.resolve(__dirname, './self_signed_ssl.crt'), 'utf8')\n}\n\nhttp.createServer(app).listen(3000);\nhttps.createServer(certificate, app).listen(3001);\n```\n\n### Configure Strategy\n\nConfiguration is exactly the same as with [passport-facebook](https://github.com/jaredhanson/passport-facebook) except the module name is `'passport-facebook-canvas'` instead of `'passport-facebook'`.\n\n```javascript\nvar FacebookStrategy = require('passport-facebook-canvas');\n\npassport.use(new FacebookStrategy({\n    clientID: FACEBOOK_APP_ID,\n    clientSecret: FACEBOOK_APP_SECRET,\n    callbackURL: \"https://apps.facebook.com/yourgame\"\n  },\n  function(accessToken, refreshToken, profile, done) {\n    User.findOrCreate({ facebookId: profile.id }, function (err, user) {\n      return done(err, user);\n    });\n  }\n));\n```\n\n### Authentication Routes\n\nConfiguration is exactly the same as with [passport-facebook](https://github.com/jaredhanson/passport-facebook) except the strategy name is `'facebook-canvas'` instead of `'facebook'`.\n\n```javascript\napp.get('/auth/facebook', passport.authenticate('facebook-canvas', { successRedirect: '/',\n                                             failureRedirect: '/error' }));\n```\n\n### Canvas Route\n\nThis is the `Secure Canvas Url` route that Facebook will POST data to.\n\n**Note** If this is the first time the app has seen this user then redirect to `failureRedirect`.\n\n```javascript\napp.post('/auth/facebook/canvas', \n  passport.authenticate('facebook-canvas', { successRedirect: '/',\n                                             failureRedirect: '/auth/facebook/canvas/autologin' }));\n```\n\n### Auto Login Route\n\nWe cannot forward the user to another URL via HTTP redirect so we have to use a client-side js **hack** instead.\n\n```javascript\napp.get('/auth/facebook/canvas/autologin', function( req, res ){\n  res.send( '\u003c!DOCTYPE html\u003e' +\n            '\u003chtml\u003e' +\n              '\u003cbody\u003e' +\n                '\u003cscript type=\"text/javascript\"\u003e' +\n                  'top.location.replace(\"/auth/facebook\");' +\n                '\u003c/script\u003e' +\n              '\u003c/body\u003e' +\n            '\u003c/html\u003e' );\n});\n```\nPlease suggest a better solution: https://developers.facebook.com/docs/appsonfacebook/tutorial/#canvas\n\n### Done\n\nNow you should be able to navigate to your app page: https://apps.facebook.com/myapp/ and be prompted to approve the app. On subsequent visits you should be logged in automatically.\n\n### License\n\n(The MIT License)\n\nCopyright (c) 2013 Peter Johnson \u0026lt;@insertcoffee\u0026gt;\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmissinglink%2Fpassport-facebook-canvas","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmissinglink%2Fpassport-facebook-canvas","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmissinglink%2Fpassport-facebook-canvas/lists"}