{"id":28076669,"url":"https://github.com/jaredhanson/passport-google-openidconnect","last_synced_at":"2025-09-14T20:46:19.625Z","repository":{"id":57150298,"uuid":"435937525","full_name":"jaredhanson/passport-google-openidconnect","owner":"jaredhanson","description":"Google authentication strategy for Passport and Node.js.","archived":false,"fork":false,"pushed_at":"2023-04-27T00:46:39.000Z","size":38,"stargazers_count":14,"open_issues_count":5,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-13T02:05:31.182Z","etag":null,"topics":["google","openid-connect","passport"],"latest_commit_sha":null,"homepage":"https://www.passportjs.org/packages/passport-google-oidc/?utm_source=github\u0026utm_medium=referral\u0026utm_campaign=passport-google-oidc\u0026utm_content=about","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/jaredhanson.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","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},"funding":{"github":"jaredhanson"}},"created_at":"2021-12-07T15:42:56.000Z","updated_at":"2024-12-08T05:25:56.000Z","dependencies_parsed_at":"2024-06-18T21:31:17.394Z","dependency_job_id":"fd76ac42-607d-4548-86ce-dccc738bbc1f","html_url":"https://github.com/jaredhanson/passport-google-openidconnect","commit_stats":{"total_commits":21,"total_committers":1,"mean_commits":21.0,"dds":0.0,"last_synced_commit":"fcf969355d5751abeffa9f065cc79b6008a08c73"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/jaredhanson/passport-google-openidconnect","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredhanson%2Fpassport-google-openidconnect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredhanson%2Fpassport-google-openidconnect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredhanson%2Fpassport-google-openidconnect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredhanson%2Fpassport-google-openidconnect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaredhanson","download_url":"https://codeload.github.com/jaredhanson/passport-google-openidconnect/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredhanson%2Fpassport-google-openidconnect/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261587354,"owners_count":23181271,"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":["google","openid-connect","passport"],"created_at":"2025-05-13T01:45:09.567Z","updated_at":"2025-07-04T11:39:37.125Z","avatar_url":"https://github.com/jaredhanson.png","language":"JavaScript","funding_links":["https://github.com/sponsors/jaredhanson"],"categories":[],"sub_categories":[],"readme":"# passport-google-oidc\n\n[Passport](https://www.passportjs.org/) strategy for authenticating with\n[Google](https://www.google.com/) using [OpenID Connect](https://www.passportjs.org/features/openid-connect/).\n\nThis module lets you authenticate using Google in your Node.js applications.\nBy plugging into Passport, Sign In with Google can be easily and unobtrusively\nintegrated into any application or framework that supports\n[Connect](https://github.com/senchalabs/connect#readme)-style middleware,\nincluding [Express](https://expressjs.com/).\n\n\u003cdiv align=\"center\"\u003e\n\n:seedling: [Tutorial](https://www.passportjs.org/tutorials/google/?utm_source=github\u0026utm_medium=referral\u0026utm_campaign=passport-google-oidc\u0026utm_content=nav-tutorial) •\n:heart: [Sponsors](https://www.passportjs.org/sponsors/?utm_source=github\u0026utm_medium=referral\u0026utm_campaign=passport-google-oidc\u0026utm_content=nav-sponsors)\n\n\u003c/div\u003e\n\n\u003cdiv align=\"right\"\u003e\n  \u003csup\u003eDeveloped by \u003ca href=\"#authors\"\u003eJared Hanson\u003c/a\u003e.\u003c/sub\u003e\n\u003c/div\u003e\n\n## Install\n\n```sh\n$ npm install passport-google-oidc\n```\n\n## Usage\n\n#### Register Application\n\nThe Google strategy authenticates users using their Google account.  Before your\napplication can make use of Google's authentication system, you must first\n[register](https://support.google.com/cloud/answer/6158849) your app to use\nOAuth 2.0 with Google APIs.  Once registered, a client ID and secret will be\nissued which are used by Google to identify your app.\n\n#### Configure Strategy\n\nOnce you've [registered your application](#register-application), the strategy\nneeds to be configured with your application's client ID and secret, along with\nits OAuth 2.0 redirect endpoint.\n\nThe strategy takes a `verify` function as an argument, which accepts `issuer`\nand `profile` as arguments.  `issuer` is set to `https://accounts.google.com`,\nindicating that the user used Google to log in.  `profile` contains the user's\n[profile information](https://www.passportjs.org/reference/normalized-profile/)\nstored in their Google account.  When authenticating a user, this strategy uses\nthe OpenID Connect protocol to obtain this information via a sequence of\nredirects and API requests to Google.\n\nThe `verify` function is responsible for determining the user to which the\nGoogle account belongs.  In cases where the account is logging in for the\nfirst time, a new user record is typically created automatically.  On subsequent\nlogins, the existing user record will be found via its relation to the Google\naccount.\n\nBecause the `verify` function is supplied by the application, the app is free to\nuse any database of its choosing.  The example below illustrates usage of a SQL\ndatabase.\n\n```js\nvar GoogleStrategy = require('passport-google-oidc');\n\npassport.use(new GoogleStrategy({\n    clientID: process.env['GOOGLE_CLIENT_ID'],\n    clientSecret: process.env['GOOGLE_CLIENT_SECRET'],\n    callbackURL: 'https://www.example.com/oauth2/redirect/google'\n  },\n  function verify(issuer, profile, cb) {\n    db.get('SELECT * FROM federated_credentials WHERE provider = ? AND subject = ?', [\n      issuer,\n      profile.id\n    ], function(err, cred) {\n      if (err) { return cb(err); }\n      \n      if (!cred) {\n        // The account at Google has not logged in to this app before.  Create a\n        // new user record and associate it with the Google account.\n        db.run('INSERT INTO users (name) VALUES (?)', [\n          profile.displayName\n        ], function(err) {\n          if (err) { return cb(err); }\n          \n          var id = this.lastID;\n          db.run('INSERT INTO federated_credentials (user_id, provider, subject) VALUES (?, ?, ?)', [\n            id,\n            issuer,\n            profile.id\n          ], function(err) {\n            if (err) { return cb(err); }\n            \n            var user = {\n              id: id,\n              name: profile.displayName\n            };\n            return cb(null, user);\n          });\n        });\n      } else {\n        // The account at Google has previously logged in to the app.  Get the\n        // user record associated with the Google account and log the user in.\n        db.get('SELECT * FROM users WHERE id = ?', [ cred.user_id ], function(err, user) {\n          if (err) { return cb(err); }\n          if (!user) { return cb(null, false); }\n          return cb(null, user);\n        });\n      }\n    });\n  }\n));\n```\n\n#### Define Routes\n\nTwo routes are needed in order to allow users to log in with their Google\naccount.  The first route redirects the user to the Google, where they will\nauthenticate:\n\n```js\napp.get('/login/google', passport.authenticate('google'));\n```\n\nThe second route processes the authentication response and logs the user in,\nafter Google redirects the user back to the app:\n\n```js\napp.get('/oauth2/redirect/google',\n  passport.authenticate('google', { failureRedirect: '/login', failureMessage: true }),\n  function(req, res) {\n    res.redirect('/');\n  });\n```\n\n## Documentation\n\n* [Using OAuth 2.0 to Access Google APIs](https://developers.google.com/identity/protocols/oauth2/)\n\n  Official Google documentation on how to use OAuth 2.0 to access Google APIs.\n\n## Examples\n\n* [todos-express-google](https://github.com/passport/todos-express-google)\n\n  Illustrates how to use the Google strategy within an Express application.  For\n  developers new to Passport and getting started, a [tutorial](https://www.passportjs.org/tutorials/google/)\n  is available.\n\n## Related Packages\n\n* [passport-google-oauth20](https://www.passportjs.org/packages/passport-google-oauth20/)\n\n  Passport strategy for authenticating with Google using OAuth 2.0.\n\n## Authors\n\n- [Jared Hanson](https://www.jaredhanson.me/) { [![WWW](https://raw.githubusercontent.com/jaredhanson/jaredhanson/master/images/globe-12x12.svg)](https://www.jaredhanson.me/) [![Facebook](https://raw.githubusercontent.com/jaredhanson/jaredhanson/master/images/facebook-12x12.svg)](https://www.facebook.com/jaredhanson) [![LinkedIn](https://raw.githubusercontent.com/jaredhanson/jaredhanson/master/images/linkedin-12x12.svg)](https://www.linkedin.com/in/jaredhanson) [![Twitter](https://raw.githubusercontent.com/jaredhanson/jaredhanson/master/images/twitter-12x12.svg)](https://twitter.com/jaredhanson) [![GitHub](https://raw.githubusercontent.com/jaredhanson/jaredhanson/master/images/github-12x12.svg)](https://github.com/jaredhanson) }\n\n## License\n\n[The MIT License](http://opensource.org/licenses/MIT)\n\nCopyright (c) 2021-2023 Jared Hanson\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredhanson%2Fpassport-google-openidconnect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaredhanson%2Fpassport-google-openidconnect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredhanson%2Fpassport-google-openidconnect/lists"}