{"_id":"passport-google-oidc","_rev":"1-4c02cfe1ac8b0f400b80988ee5db690c","name":"passport-google-oidc","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"passport-google-oidc","version":"0.1.0","description":"Google authentication strategy for Passport using OpenID Connect.","keywords":["passport","google","auth","authn","authentication","identity"],"author":{"name":"Jared Hanson","email":"jaredhanson@gmail.com","url":"https://www.jaredhanson.me/"},"repository":{"type":"git","url":"git://github.com/jaredhanson/passport-google-openidconnect.git"},"bugs":{"url":"http://github.com/jaredhanson/passport-google-openidconnect/issues"},"funding":{"type":"github","url":"https://github.com/sponsors/jaredhanson"},"license":"MIT","licenses":[{"type":"MIT","url":"https://opensource.org/licenses/MIT"}],"main":"./lib","dependencies":{"passport-openidconnect":"0.1.x"},"devDependencies":{"make-node":"0.4.6","mocha":"2.x.x","chai":"2.x.x","chai-passport-strategy":"1.x.x"},"engines":{"node":">= 0.4.0"},"scripts":{"test":"mocha --require ./test/bootstrap/node --recursive"},"gitHead":"4b15e743bbffcebd5ce89cf86cd0b4f9bb25ac9b","homepage":"https://github.com/jaredhanson/passport-google-openidconnect#readme","_id":"passport-google-oidc@0.1.0","_nodeVersion":"14.16.1","_npmVersion":"6.14.12","dist":{"integrity":"sha512-/TtFXaWvmubm5kXNoJMyzBfxhnZ0lnBPA6w6rmQMP9klmHZf0ArE8IrIEt3yAHoiDzGx4eTO7YasKQFbPsNtVA==","shasum":"585790ba03864c0238cb89912d7e2a958086b5b0","tarball":"https://registry.npmjs.org/passport-google-oidc/-/passport-google-oidc-0.1.0.tgz","fileCount":9,"unpackedSize":12312,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhtTj+CRA9TVsSAnZWagAA8ZoQAJPLnF9AVJyeIFxQPkG+\nwLO2fo9gxFUAllMOlTZcjINJ6xZCUGSxMmaMwkwp/6MqjaartBqDOw8m/D24\nxn3en+wBf4hM3yLj44Lx5AvDvq8nHc+xf3/QZ0tcD8X46bfFdiTcBB6couf4\n1brfdhUzXUgPJ2EwJUFBziOWXgyx5sLDcucV3G3kafWmpWhZ84apb89VJaio\n9M9cAs9+kwon+Ykdabi9c7FLax8FYzycw1iC9R8M1jtOTh1/K1yOGK4pla68\n1XFJrDh8JpprMIewiUDrbqKszJrcBwaf6cPruQcsq9uxfAegXXhRqB+fRLXJ\ndHJy4Ebylf9yLSiKaBXhS3IN2FiqOXKwusOsFJy4oDlufH3rE1wHwKiG7kWH\nxnnnZi9B+a6v+d5Q/w7XT5Q1qsFx8NIgkTPcqBhufQOEPPZoAg7iHf74wlYh\nQofX3YIvcqL3MqHE2OVeex3XP8cHhlDR+Pd+BGTDoFLrs9t8ye9FYn9tl0xM\nf3CzZDLdDNQGU8fSj/cLTsIiiDqMHwF5IY1xjDirLzMW3wsOle2kDvR/iwAS\nd0fRJuBahqa0OAdNElY1SPKkwr8QhNCPyFcsE19J8jYzXe7YHmBhRyGPFNU7\nJPRyDiC8YnlAhGEuj1vNs4pymkl2ow4A2n6Fy/E/QUeG/WFnNfE8bl5pvY1L\nEOk7\r\n=MuIN\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGf2M+906J0rpJtTv9OW/qZguI2EB7PZvHWo+xTa9D+VAiBHf+w7m5NiHAlLBw0vyvOqHDnMX4tU4Voxtn9WE50Sxw=="}]},"_npmUser":{"name":"jaredhanson","email":"jaredhanson@gmail.com"},"directories":{},"maintainers":[{"name":"jaredhanson","email":"jaredhanson@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/passport-google-oidc_0.1.0_1639266558131_0.6347806426750096"},"_hasShrinkwrap":false}},"time":{"created":"2021-12-11T23:49:18.131Z","0.1.0":"2021-12-11T23:49:18.299Z","modified":"2022-05-12T15:41:07.741Z"},"maintainers":[{"name":"jaredhanson","email":"jaredhanson@gmail.com"}],"description":"Google authentication strategy for Passport using OpenID Connect.","homepage":"https://github.com/jaredhanson/passport-google-openidconnect#readme","keywords":["passport","google","auth","authn","authentication","identity"],"repository":{"type":"git","url":"git://github.com/jaredhanson/passport-google-openidconnect.git"},"author":{"name":"Jared Hanson","email":"jaredhanson@gmail.com","url":"https://www.jaredhanson.me/"},"bugs":{"url":"http://github.com/jaredhanson/passport-google-openidconnect/issues"},"license":"MIT","readme":"# passport-google-oidc\n\n[Passport](https://www.passportjs.org/) strategy for authenticating with\n[Google](https://www.google.com/) using OpenID Connect.\n\nThis module lets you authenticate using Google in your Node.js applications.\nBy plugging into Passport, Google authentication can be easily and\nunobtrusively integrated into any application or framework that supports\n[Connect](https://github.com/senchalabs/connect#readme)-style middleware,\nincluding [Express](https://expressjs.com/).\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.  To register, complete the\nfollowing steps:\n\n1. Go to the [Google Cloud Platform console](https://console.cloud.google.com/).\n\n2. From the projects list, select a project or create a new one.\n\n3. Navigate to the [APIs & Services](https://console.cloud.google.com/apis) page\nand select [Credentials](https://console.cloud.google.com/apis/credentials).\n\n4. If you have an existing application, it will be listed under **OAuth 2.0\nClient IDs**.  Click **Edit OAuth client** to obtain the client ID and secret,\nand proceed to [configure the strategy](#configure-strategy).  Otherwise,\ncontinue.\n\n5. If you have not already done so, [configure](https://support.google.com/cloud/answer/10311615)\nthe [OAuth consent screen](https://console.cloud.google.com/apis/credentials/consent).\nSelect **External** to make your application available to any user with a Google\naccount.  Complete the app registration process by entering the app name,\nsupport email, and developer contact information.\n\n6. Click **Create Credentials**, then select **OAuth client ID**.\n\n7. Select **Web application** as **Application type**.\n\n8. Click **Add URI** under **Authorized Redirect URIs**.  Enter the URL of your\napplication's OAuth 2.0 redirect endpoint.  If you are using the example app,\nenter `http://localhost:3000/oauth2/redirect`.\n\n9. Click **Create** to create the OAuth client.  The following screen will\ndisplay your client ID and secret.  Proceed to [configure the strategy](#configure-strategy).\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\nprofile information stored in their Google account.  When authenticating a\nuser, this strategy uses the OpenID Connect protocol to obtain this information\nvia a sequence of redirects 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'\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      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            var user = {\n              id: id.toString(),\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',\n  passport.authenticate('google', { failureRedirect: '/login', failureMessage: true }),\n  function(req, res) {\n    res.redirect('/');\n  });\n```\n\n## Documentation\n\nRefer to [Using OAuth 2.0 to Access Google APIs](https://developers.google.com/identity/protocols/oauth2/)\nfor more information on integrating your application with Google APIs using\nOAuth 2.0 and OpenID Connect.\n\n## License\n\n[The MIT License](http://opensource.org/licenses/MIT)\n\nCopyright (c) 2021 Jared Hanson <[https://www.jaredhanson.me/](https://www.jaredhanson.me/)>\n","readmeFilename":"README.md"}