{"id":19956419,"url":"https://github.com/drudge/passport-twitter-token","last_synced_at":"2025-05-03T20:32:05.565Z","repository":{"id":5429955,"uuid":"6622148","full_name":"drudge/passport-twitter-token","owner":"drudge","description":"Passport strategy for authenticating with Twitter tokens using the OAuth 1.0a API.","archived":false,"fork":false,"pushed_at":"2022-04-07T03:40:28.000Z","size":61,"stargazers_count":52,"open_issues_count":5,"forks_count":19,"subscribers_count":2,"default_branch":"dev","last_synced_at":"2025-05-02T21:59:38.197Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drudge.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-11-09T23:26:59.000Z","updated_at":"2025-02-28T03:02:28.000Z","dependencies_parsed_at":"2022-07-06T17:30:24.745Z","dependency_job_id":null,"html_url":"https://github.com/drudge/passport-twitter-token","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drudge%2Fpassport-twitter-token","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drudge%2Fpassport-twitter-token/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drudge%2Fpassport-twitter-token/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drudge%2Fpassport-twitter-token/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drudge","download_url":"https://codeload.github.com/drudge/passport-twitter-token/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252252985,"owners_count":21718768,"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-11-13T01:34:14.427Z","updated_at":"2025-05-03T20:32:00.559Z","avatar_url":"https://github.com/drudge.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# passport-twitter-token\n\n[![Build Status](https://travis-ci.org/drudge/passport-twitter-token.svg)](https://travis-ci.org/drudge/passport-twitter-token)\n[![Coverage Status](https://coveralls.io/repos/drudge/passport-twitter-token/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/drudge/passport-twitter-token?branch=master)\n![Downloads](https://img.shields.io/npm/dm/passport-twitter-token.svg)\n![Downloads](https://img.shields.io/npm/dt/passport-twitter-token.svg)\n![npm version](https://img.shields.io/npm/v/passport-twitter-token.svg)\n![dependencies](https://img.shields.io/david/drudge/passport-twitter-token.svg)\n![dev dependencies](https://img.shields.io/david/dev/drudge/passport-twitter-token.svg)\n![License](https://img.shields.io/npm/l/passport-twitter-token.svg)\n\n[Passport](http://passportjs.org/) strategy for authenticating with [Twitter](http://twitter.com/) tokens using the OAuth 1.0a API.\n\nThis module lets you authenticate using Twitter in your Node.js applications.\nBy plugging into Passport, Twitter authentication can be easily and unobtrusively integrated into any application or framework that supports [Connect](http://www.senchalabs.org/connect/)-style middleware, including [Express](http://expressjs.com/).\n\n### Installation\n\n#### Using npm\n\n    $ npm install passport-twitter-token\n\n#### Using yarn\n\n    $ yarn add passport-twitter-token\n\n## Usage\n\n### Configure Strategy\n\nThe Twitter authentication strategy authenticates users using a Twitter account and OAuth tokens.\nThe strategy requires a `verify` callback, which receives the access token and corresponding secret as arguments, as well as `profile` which contains the authenticated user's Twitter profile.\nThe `verify` callback must call `done` providing a user to complete authentication.\n\nIn order to identify your application to Twitter, specify the consumer key, consumer secret, and callback URL within `options`.\nThe consumer key and secret are obtained by [creating an application](https://dev.twitter.com/apps) at Twitter's [developer](https://dev.twitter.com/) site.\n\nOptional fields:\n - `includeEmail` - Boolean \n - `includeStatus` - Boolean\n - `includeEntities` - Boolean\n - `userProfileURL` - Default `https://api.twitter.com/1.1/account/verify_credentials.json`\n \n```javascript\nconst TwitterTokenStrategy = require('passport-twitter-token');\n\npassport.use(new TwitterTokenStrategy({\n    consumerKey: TWITTER_CONSUMER_KEY,\n    consumerSecret: TWITTER_CONSUMER_SECRET\n  }, (token, tokenSecret, profile, done) =\u003e {\n    User.findOrCreate({ twitterId: profile.id }, (error, user) =\u003e {\n      return done(error, user);\n    });\n  }\n));\n```\n\n### Authenticate Requests\n\nUse `passport.authenticate()`, specifying the `'twitter-token'` strategy, to authenticate requests.\n\nFor example, as route middleware in an [Express](http://expressjs.com/) application:\n\n```javascript\napp.post('/auth/twitter/token',\n  passport.authenticate('twitter-token'),\n  (req, res) =\u003e {\n    // do something with req.user\n    res.send(req.user ? 200 : 401);\n  }\n);\n```\n\nOr as action in Sails framework:\n\n```javascript\n// api/controllers/AuthController.js\nmodule.exports = {\n  twitter: (req, res) =\u003e {\n    passport.authenticate('twitter-token', (error, user, info) =\u003e {\n      // do your stuff with user\n    })(req, res);\n  }\n};\n```\n\nExecute a request (GET or POST) to created route with the following data:\n\n```\nGET /auth/twitter/token?oauth_token=\u003cTOKEN\u003e\u0026oauth_token_secret=\u003cTOKEN_SECRET\u003e\u0026user_id=\u003cUSER_ID\u003e\n```\n\n### Performing Twitter Reverse Auth Step 1 Server-Side\n\nTo remove the need to embed the consumer secret in your client application, you can setup a route to perform step 1 on the server-side.\n\nFor example, as route in an [Express](http://expressjs.com/) application using the [request](https://github.com/mikeal/request) module:\n\n```javascript\nconst request = require('request');\n\napp.post('/auth/twitter/reverse', (req, res) =\u003e {\n  request.post({\n    url: 'https://api.twitter.com/oauth/request_token',\n    oauth: {\n      consumer_key: app.set('twitter client key'),\n      consumer_secret: app.set('twitter client secret')\n    },\n    form: { x_auth_mode: 'reverse_auth' }\n  }, (err, r, body) =\u003e {\n    if (err) {\n      return res.send(500, { message: e.message });\n    }\n\n    if (body.indexOf('OAuth') !== 0) {\n      return res.send(500, { message: 'Malformed response from Twitter' });\n    }\n\n    res.send({ x_reverse_auth_parameters: body });\n  });\n};\n```\n\n## Credits\n\n  - [Nicholas Penree](http://github.com/drudge)\n  - [Jared Hanson](http://github.com/jaredhanson)\n  - [Eugene Obrezkov](http://github.com/ghaiklor)\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2012-2015 Nicholas Penree\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrudge%2Fpassport-twitter-token","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrudge%2Fpassport-twitter-token","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrudge%2Fpassport-twitter-token/lists"}