{"id":17399246,"url":"https://github.com/feross/login-with-twitter","last_synced_at":"2025-04-09T09:05:16.953Z","repository":{"id":55843641,"uuid":"80395022","full_name":"feross/login-with-twitter","owner":"feross","description":"Login with Twitter. OAuth without the nonsense.","archived":false,"fork":false,"pushed_at":"2020-12-11T11:11:57.000Z","size":24,"stargazers_count":123,"open_issues_count":5,"forks_count":30,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-02T08:11:17.555Z","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/feross.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2017-01-30T05:01:06.000Z","updated_at":"2024-05-12T04:29:05.000Z","dependencies_parsed_at":"2022-08-15T07:50:21.174Z","dependency_job_id":null,"html_url":"https://github.com/feross/login-with-twitter","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/feross%2Flogin-with-twitter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Flogin-with-twitter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Flogin-with-twitter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/feross%2Flogin-with-twitter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/feross","download_url":"https://codeload.github.com/feross/login-with-twitter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248008631,"owners_count":21032556,"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-16T15:14:01.220Z","updated_at":"2025-04-09T09:05:16.929Z","avatar_url":"https://github.com/feross.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# login-with-twitter [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]\n\n[travis-image]: https://img.shields.io/travis/feross/login-with-twitter/master.svg\n[travis-url]: https://travis-ci.org/feross/login-with-twitter\n[npm-image]: https://img.shields.io/npm/v/login-with-twitter.svg\n[npm-url]: https://npmjs.org/package/login-with-twitter\n[downloads-image]: https://img.shields.io/npm/dm/login-with-twitter.svg\n[downloads-url]: https://npmjs.org/package/login-with-twitter\n[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg\n[standard-url]: https://standardjs.com\n\n### Login with Twitter. OAuth without the nonsense.\n\n## Features\n\nThis module is designed to be the lightest possible wrapper on Twitter OAuth.\n\nAll this in \u003c 100 lines of code.\n\n## Install\n\n```\nnpm install login-with-twitter\n```\n\n## Usage\n\nSet up two routes on your web sever. We'll call them `/twitter` and\n`/twitter/callback`, but they can be named anything.\n\n### Initialization\nInitialize this module with the consumer key and secret for your Twitter App you created with an Twitter Developer account.\n\n```js\nconst LoginWithTwitter = require('login-with-twitter')\n\nconst tw = new LoginWithTwitter({\n  consumerKey: '\u003cyour consumer key\u003e',\n  consumerSecret: '\u003cyour consumer secret\u003e',\n  callbackUrl: 'https://example.com/twitter/callback'\n})\n```\n\n### Login\n\nCall `login` from your `/twitter` route, saving the OAuth `tokenSecret` to use later. In this example, we use the request session (using, for example, [express-session](https://www.npmjs.com/package/express-session)).\n\n```js \napp.get('/twitter', (req, res) =\u003e {\n  tw.login((err, tokenSecret, url) =\u003e {\n    if (err) {\n      // Handle the error your way\n    }\n    \n    // Save the OAuth token secret for use in your /twitter/callback route\n    req.session.tokenSecret = tokenSecret\n    \n    // Redirect to the /twitter/callback route, with the OAuth responses as query params\n    res.redirect(url)\n  })\n})\n```\n\n### Callback\n\nThen, call `callback` from your `/twitter/callback` route. The request will include `oauth_token` and `oauth_verifier` in the URL, accessible with `req.query`. Pass those into `callback`, along with the OAuth `tokenSecret` you saved in the `login` callback above, and a callback that handles a `user` object that this module will return.\n\n```js\napp.get('/twitter/callback', (req, res) =\u003e {\n  tw.callback({\n    oauth_token: req.query.oauth_token,\n    oauth_verifier: req.query.oauth_verifier\n  }, req.session.tokenSecret, (err, user) =\u003e {\n    if (err) {\n      // Handle the error your way\n    }\n    \n    // Delete the tokenSecret securely\n    delete req.session.tokenSecret\n    \n    // The user object contains 4 key/value pairs, which\n    // you should store and use as you need, e.g. with your\n    // own calls to Twitter's API, or a Twitter API module\n    // like `twitter` or `twit`.\n    // user = {\n    //   userId,\n    //   userName,\n    //   userToken,\n    //   userTokenSecret\n    // }\n    req.session.user = user\n    \n    // Redirect to whatever route that can handle your new Twitter login user details!\n    res.redirect('/')\n  });\n});\n```\n\n### Logout\nIf you want to implement logout, simply delete the `user` object stored in the session.\n\n---\n\nFor more information, check out the implementation in [index.js](index.js).\n\n## license\n\nMIT. Copyright (c) [Feross Aboukhadijeh](http://feross.org).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeross%2Flogin-with-twitter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffeross%2Flogin-with-twitter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffeross%2Flogin-with-twitter/lists"}