{"id":22096963,"url":"https://github.com/pitops/passgate","last_synced_at":"2025-03-24T01:18:38.862Z","repository":{"id":37735498,"uuid":"190413743","full_name":"pitops/passgate","owner":"pitops","description":"Simple and unobtrusive authentication for third-party OAuth2 providers","archived":false,"fork":false,"pushed_at":"2022-12-10T18:16:59.000Z","size":685,"stargazers_count":0,"open_issues_count":13,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-18T21:09:32.015Z","etag":null,"topics":["auth","express-middleware","google-oauth","third-party-authentication"],"latest_commit_sha":null,"homepage":"","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/pitops.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":"2019-06-05T14:47:06.000Z","updated_at":"2019-08-12T10:07:12.000Z","dependencies_parsed_at":"2023-01-26T05:30:49.632Z","dependency_job_id":null,"html_url":"https://github.com/pitops/passgate","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/pitops%2Fpassgate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pitops%2Fpassgate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pitops%2Fpassgate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pitops%2Fpassgate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pitops","download_url":"https://codeload.github.com/pitops/passgate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245191590,"owners_count":20575250,"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":["auth","express-middleware","google-oauth","third-party-authentication"],"created_at":"2024-12-01T04:13:40.906Z","updated_at":"2025-03-24T01:18:38.839Z","avatar_url":"https://github.com/pitops.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"\" rel=\"noopener\"\u003e\n \u003cimg src=\"https://i.imgur.com/9f5E2Ud.png\" alt=\"Passgate\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003ch2 align=\"center\"\u003ePassgate\u003c/h3\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n[![Status](https://img.shields.io/badge/status-active-success.svg)]()\n[![GitHub Issues](https://img.shields.io/github/issues/pitops/passgate.svg)](https://github.com/pitops/passgate/issues)\n[![GitHub Pull Requests](https://img.shields.io/github/issues-pr/pitops/passgate.svg)](https://github.com/pitops/passgate/pulls)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](/LICENSE)\n\n\u003c/div\u003e\n\n## \u003cp align = \"center\"\u003e💡 Easy third-party authentication middleware for express\u003c/p\u003e\n\n## 📝 Table of Contents\n\n- [About](#about)\n- [Getting Started](#getting_started)\n- [TODO](../TODO.md)\n- [Authors](#authors)\n\n## 🧐 About \u003ca name = \"about\"\u003e\u003c/a\u003e\n\nPassgate is yet another OAuth2 library heavily inspired from passport with the subtle difference of having everything configured in one place.\n\nThe purpose of passgate is to provide a simple and easy unobtrusive way of authenticating with third party OAUTH2 providers. **Right now, it only works with Google OAuth2** but it will be expanded in the near future.\n\n## 🏁 Getting Started \u003ca name = \"getting_started\"\u003e\u003c/a\u003e\n\nIn general, Passgate is a middleware that gets passed a config object and thats it. It will do the dirty work for you.\n\n### Step 1\n\nFirst install the npm package\n\n```bash\nnpm i passgate\n```\n\n### Step 2\n\nCreate a file named `google.js` and import the following.\n\n```javascript\nconst GoogleStrategy = {\n  google: {\n    clientID: 'GOOGLE_CLIENT_ID',\n    clientSecret: 'GOOGLE_CLIENT_SECRET',\n    authPath: '/auth/google',\n    callbackPath: '/auth/google/callback',\n    revokePath: '/auth/google/revoke',\n    callbackURL: `${LOCALHOST_URL}/auth/google/callback`,\n    scope: ['https://www.googleapis.com/auth/youtube'],\n    access_type: 'offline',\n    successRedirect: '/',\n    failureRedirect: '/login',\n    eventCallbacks: {\n      onAuthSuccess,\n      onTokensRefresh,\n      onAccessRevoke\n    }\n  }\n}\n\nfunction onAuthSuccess(\n  {accessToken, refreshToken, tokenExpiryDate, profile},\n  done\n) {\n  console.log({accessToken, refreshToken, tokenExpiryDate, profile})\n  // do DB stuff\n  done() // this must be called after you finish with DB stuff\n}\n\nfunction onTokensRefresh({access_token, refresh_token, expiry_date}) {\n  console.log({access_token, refresh_token, expiry_date})\n}\n\nfunction onAccessRevoke(done) {\n  // do database level stuff\n\n  done('INSERT REFRESH TOKEN') // here pass the actual refreshToken from your db\n}\n\nmodule.exports = GoogleStrategy\n```\n\nThe above code can be called a Strategy. In this case for Google. As you can see everything is in once place for authenticating and de-authenticating with Google.\n\n**Make sure you get your CLIENT_ID and CLIENT_SECRET** from [Google dev console](https://console.developers.google.com/)\n\n# Step 3\n\n```javascript\n// server.js\n\nconst express = require('express')\nconst passgate = require('passgate')\n\nconst GoogleStrategy = require('./google')\n\nconst app = express()\nconst port = process.env.PORT || 3000\n\npassgate.init(GoogleStrategy)\n\napp.use(passgate)\n\napp.get('/', async (req, res) =\u003e {\n  res.send('Hello world')\n})\n\napp.listen(port, () =\u003e console.log(`App running on ${port}!`))\n```\n\n### Prerequisites\n\nRight now Passgate only works with **Express** so make sure your project supports that.\n\n## TODO\n\n- [x] Add Google OAUTH\n- [ ] Add Facebook OAUTH\n- [ ] Add Github OAUTH\n\n## ✍️ Authors \u003ca name = \"authors\"\u003e\u003c/a\u003e\n\n- [@pitops](https://github.com/pitops) - Idea \u0026 Initial work\n\n## Acknowledgements\n\n\u003ca href='https://dryicons.com/icon/gate-icon-11381'\u003e Icon by Dryicons \u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpitops%2Fpassgate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpitops%2Fpassgate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpitops%2Fpassgate/lists"}