{"id":22080036,"url":"https://github.com/superfaceai/passport-twitter-oauth2","last_synced_at":"2026-03-05T02:31:05.761Z","repository":{"id":57163616,"uuid":"450470258","full_name":"superfaceai/passport-twitter-oauth2","owner":"superfaceai","description":"Twitter OAuth 2.0 Strategy for Passport for accessing Twitter API v2","archived":false,"fork":false,"pushed_at":"2025-02-06T20:51:54.000Z","size":365,"stargazers_count":31,"open_issues_count":21,"forks_count":12,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-10-12T15:38:36.454Z","etag":null,"topics":["oauth2","passport","passport-strategy","passport-twitter","twitter","twitter-api","twitter-api-v2"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/superfaceai.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-01-21T11:46:47.000Z","updated_at":"2025-04-11T14:18:40.000Z","dependencies_parsed_at":"2025-02-24T16:15:15.254Z","dependency_job_id":"f09e67f9-a94b-4946-b093-473b2b0f27d6","html_url":"https://github.com/superfaceai/passport-twitter-oauth2","commit_stats":{"total_commits":119,"total_committers":9,"mean_commits":"13.222222222222221","dds":0.5630252100840336,"last_synced_commit":"885ed094b1ed6a4d484d937e289266018b4b34cd"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/superfaceai/passport-twitter-oauth2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/superfaceai%2Fpassport-twitter-oauth2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/superfaceai%2Fpassport-twitter-oauth2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/superfaceai%2Fpassport-twitter-oauth2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/superfaceai%2Fpassport-twitter-oauth2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/superfaceai","download_url":"https://codeload.github.com/superfaceai/passport-twitter-oauth2/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/superfaceai%2Fpassport-twitter-oauth2/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30107201,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-05T01:39:18.192Z","status":"online","status_checked_at":"2026-03-05T02:00:06.710Z","response_time":93,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["oauth2","passport","passport-strategy","passport-twitter","twitter","twitter-api","twitter-api-v2"],"created_at":"2024-11-30T23:12:00.700Z","updated_at":"2026-03-05T02:31:05.733Z","avatar_url":"https://github.com/superfaceai.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Twitter OAuth 2.0 Strategy for Passport\n\n**`@superfaceai/passport-twitter-oauth2`**\n\n[![npm](https://img.shields.io/npm/v/@superfaceai/passport-twitter-oauth2)](https://www.npmjs.com/package/@superfaceai/passport-twitter-oauth2)\n[![license](https://img.shields.io/npm/l/@superfaceai/passport-twitter-oauth2)](LICENSE)\n![TypeScript](https://img.shields.io/static/v1?message=TypeScript\u0026\u0026logoColor=ffffff\u0026color=007acc\u0026labelColor=5c5c5c\u0026label=built%20with)\n[![GitHub Discussions](https://img.shields.io/github/discussions/superfaceai/.github?logo=github\u0026logoColor=fff)](https://github.com/orgs/superfaceai/discussions)\n\n[Passport](http://passportjs.org/) strategy for authenticating with Twitter using [OAuth 2.0](https://developer.twitter.com/en/docs/authentication/oauth-2-0).\n\nThis module lets you authenticate using Twitter in your Node.js applications.\nBy plugging into Passport, Twitter authentication can be integrated into any application or framework that supports\n[Connect](http://www.senchalabs.org/connect/)-style middleware, including\n[Express](http://expressjs.com/).\n\n[Twitter announced OAuth 2.0 general availability](https://twittercommunity.com/t/announcing-oauth-2-0-general-availability/163555) on December 14 2021 and encourages developers to use Twitter API v2.0 with OAuth 2.0 authentication.\n\nTwitter OAuth 2.0 implementation specifics:\n\n- [PKCE](https://datatracker.ietf.org/doc/html/rfc7636) is required\n- OAuth2 client credentials must be passed via `Authorization` header for `confidential` client types\n\n## Install\n\n```shell\nnpm install @superfaceai/passport-twitter-oauth2\n```\n\n## Usage\n\n\u003e **Note**\n\u003e Check our blog for a [complete tutorial with code explanation](https://superface.ai/blog/twitter-oauth2-passport?ref=github-passport-twitter-oauth2).\n\n#### Create an Application\n\nBefore using `@superfaceai/passport-twitter-oauth2`, you must register a project and an application with Twitter by following these steps:\n\n1. go to https://developer.twitter.com/ and either sign up for a new account or sign in with existing one\n1. sign up for Essential access; you will need to verify a phone number for your Twitter account\n1. create a project and application (Essential account is limited to a single project and application)\n1. in application settings generate OAuth 2.0 Client ID and Client Secret; mind that you cannot view the secret again later, only regenerate it\n\n#### Configure Strategy\n\nProvide OAuth 2.0 Client ID and Client Secret (from previous step)\nto the strategy constructor. The strategy\nalso requires a `verify` callback, which receives the access token and\nrefresh token as arguments, as well as `profile` which contains the\nauthenticated user's Twitter profile. The `verify` callback must call `cb`\nproviding a user to complete authentication.\n\n```javascript\npassport.use(\n  new TwitterStrategy(\n    {\n      clientType: 'confidential', //depends on your Twitter app settings, valid values are `confidential` or `public`\n      clientID: TWITTER_CLIENT_ID,\n      clientSecret: TWITTER_CLIENT_SECRET,\n      callbackURL: 'http://127.0.0.1:3000/auth/twitter/callback',\n    },\n    function (accessToken, refreshToken, profile, done) {\n      User.findOrCreate({ twitterId: profile.id }, function (err, user) {\n        return done(err, user);\n      });\n    }\n  )\n);\n```\n\n#### Authenticate Requests\n\nUse `passport.authenticate()`, specifying the `'twitter'` strategy, to\nauthenticate requests.\n\nDo not forget to configure scopes required by your application.\n\nFor example, you can use `authenticate` function as an Express route middleware:\n\n```javascript\napp.get('/auth/twitter', passport.authenticate('twitter'));\n\napp.get(\n  '/auth/twitter/callback',\n  passport.authenticate('twitter', {\n    failureRedirect: '/login',\n    scope: ['tweet.read', 'tweet.write', 'users.read'],\n  }),\n  function (req, res) {\n    // Successful authentication, redirect home.\n    res.redirect('/');\n  }\n);\n```\n\n## Examples\n\nCheck the [examples](examples/) directory for minimal working projects:\n\n- [Basic usage with plain JavaScript](examples/basic-usage/)\n- [Usage with TypeScript](examples/with-typescript/)\n\n## Where It's Being Used\n\n- [twitter-demo](https://github.com/superfaceai/twitter-demo) – Demo of social media profiles for Twitter with [Superface OneSDK][one-sdk] uses this strategy to generate access tokens.\n- [social-media-demo](https://github.com/superfaceai/social-media-demo) – Demo application handling access to multiple social media sites, content publishing, reading timelines and more.\n\n## Related Projects\n\n- [oauth2/refresh-token](https://superface.ai/oauth2/refresh-token?provider=twitter) – Profile for refreshing access tokens using [Superface OneSDK][one-sdk]\n- [passport-oauth2](https://github.com/jaredhanson/passport-oauth2) – OAuth 2.0 strategy this package builds upon.\n- [passport-twitter](https://github.com/jaredhanson/passport-twitter) – Legacy Twitter strategy which uses OAuth 1.0a.\n- [passport-twitter-oauth2](https://github.com/balanced-mt/passport-twitter-oauth2) – Original OAuth 2.0 Twitter strategy, no longer maintained.\n\n## Development\n\nWhen developing, start with cloning the repository using `git clone https://github.com/superfaceai/passport-twitter-oauth2.git`.\n\nAfter cloning, install the dependencies with `npm i`.\n\nNow the repository is ready for code changes.\n\nThe `package.json` also contains scripts (runnable by calling `npm run \u003cscript-name\u003e`):\n\n- `build` - transpile TypeScript into JavaScript\n- `format` - check the code formatting\n- `format:fix` - fix the code formatting\n- `lint` - run linter\n- `test` - run tests\n\n## Contributing\n\n**Please open an issue first if you want to make larger changes**\n\nFeel free to contribute! Please follow the [Contribution Guide](CONTRIBUTING.md).\n\n## Maintainers\n\n- [Jan Halama](https://github.com/janhalama)\n- [Jan Vlnas](https://github.com/jnv)\n\n## License\n\n`@superfaceai/passport-twitter-oauth2` project is licensed under the [MIT license](LICENSE).\n\n© 2023 Superface s.r.o.\n\n[one-sdk]: https://github.com/superfaceai/one-sdk-js\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuperfaceai%2Fpassport-twitter-oauth2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsuperfaceai%2Fpassport-twitter-oauth2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuperfaceai%2Fpassport-twitter-oauth2/lists"}