{"_id":"3chospirits-passport-google-oauth20","name":"3chospirits-passport-google-oauth20","dist-tags":{"latest":"2.0.1"},"versions":{"2.0.1":{"name":"3chospirits-passport-google-oauth20","version":"2.0.1","description":"Patched Google (OAuth 2.0) authentication strategy for Passport.","keywords":["passport","google","auth","authn","authentication","identity"],"author":{"name":"3chospirits"},"repository":{"type":"git","url":"git://github.com/3chospirits/passport-google-oauth2.git"},"bugs":{"url":"https://github.com/3chospirits/passport-google-oauth2"},"license":"MIT","licenses":[{"type":"MIT","url":"http://opensource.org/licenses/MIT"}],"main":"./lib","dependencies":{"passport-oauth2":"git+https://github.com/3chospirits/passport-google-oauth2.git"},"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":"aa776fc2baebe451f9a5b6bc738bafca7a303da6","homepage":"https://github.com/3chospirits/passport-google-oauth2#readme","_id":"3chospirits-passport-google-oauth20@2.0.1","_nodeVersion":"16.15.0","_npmVersion":"8.5.5","dist":{"integrity":"sha512-UfqHMEotqJ6TqjPP2ECt+2gsusNZenSUddetfU5gKxQwGC5IkaCv1RseW4OKGznO6igEWQQpuqBNEFqM2K0pcQ==","shasum":"73341d4692a6edd90086fd9578452a7a942875d3","tarball":"https://registry.npmjs.org/3chospirits-passport-google-oauth20/-/3chospirits-passport-google-oauth20-2.0.1.tgz","fileCount":15,"unpackedSize":24032,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICZ9svkmE2OB3pWG/ivTNqPXCYjkZnmUWcG46ZnhWPjRAiEA83Pn0P2V7r++0ytvMKiBHmyffnLTGMgGolqIPe3UroQ="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkInmbACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmrM0w/9Hnamz8XxuYAJGDvSXEqaGEdWN+8spbotOudiirU2o/QIBV6E\r\n+hqG9TW5A+w8QHDN37k/sQvU3Ta14SMyGw6VbS0C8Fn67E/J8TMSud3uWGIW\r\n7C276wB8vznJ+iSWEWQMTGea0l8nuegzIL8brzXfMfP1F3qtdaVPg6QKlS6o\r\nLUdEOMYfThXIXnqAQrdu1bWAy2luoGA/gj/LemCs36BKyPtnX7vy0dLcs3yM\r\nN9UcpAqBaLqPw8hR7lHpnRT2rKUlXsza9du3cIsliX3xV8RVq/2igIB/lHpK\r\nlTz/i2YE6DNe/W2cZpcxBHJV+auAAtbkDnj0N2jNmLMod3L1gd0lVaga6E7U\r\nOD9PZWdQUCXO3t1ZdT5LIUeWoBrvKSzo68gKYk7/Yh6YUEBKs8hZMCi4l68w\r\n0Oso+99wOEKY0oQ7OLNS8gwWJcqabEaj7vsKgF+KWIGsmhlgJ5CydkD4ow9O\r\n+NRMHMoILbgQ/zdCJzsQ6ybneTve2PuQesG21j6kJINq42y3f7zw2tL+kSqL\r\nWcxUciDCiVEzAgwtGwCNDawA+HPxMAURVM+sSMAaxPXskC2TN2F1pFWlpEoT\r\nXlwj3lylJUeBcqgw4G392FVi2GYF9GCc7OQxCJQw25AEnysZzmNMWHKVL9rP\r\nRUDDMkYkx8GJigGE3Vr1uPZSEMUTqPC51Bg=\r\n=vsuK\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"3chospirits","email":"3chospirits@gmail.com"},"directories":{},"maintainers":[{"name":"3chospirits","email":"3chospirits@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/3chospirits-passport-google-oauth20_2.0.1_1679980955379_0.8508044788491727"},"_hasShrinkwrap":false}},"time":{"created":"2023-03-28T05:22:35.378Z","2.0.1":"2023-03-28T05:22:35.608Z","modified":"2023-03-28T05:22:35.788Z"},"maintainers":[{"name":"3chospirits","email":"3chospirits@gmail.com"}],"description":"Patched Google (OAuth 2.0) authentication strategy for Passport.","homepage":"https://github.com/3chospirits/passport-google-oauth2#readme","keywords":["passport","google","auth","authn","authentication","identity"],"repository":{"type":"git","url":"git://github.com/3chospirits/passport-google-oauth2.git"},"author":{"name":"3chospirits"},"bugs":{"url":"https://github.com/3chospirits/passport-google-oauth2"},"license":"MIT","readme":"# passport-google-oauth20\n\n[Passport](https://www.passportjs.org/) strategy for authenticating with\n[Google](https://www.google.com/) using [OAuth 2.0](https://www.passportjs.org/packages/passport-oauth2/).\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<div align=\"center\">\n  \n:brain: [Understanding OAuth 2.0](https://www.passportjs.org/concepts/oauth2/?utm_source=github&utm_medium=referral&utm_campaign=passport-google-oauth20&utm_content=nav-concept) •\n:heart: [Sponsors](https://www.passportjs.org/sponsors/?utm_source=github&utm_medium=referral&utm_campaign=passport-google-oauth20&utm_content=nav-sponsors)\n\n</div>\n\n---\n\n<p align=\"center\">\n  <sup>Advertisement</sup>\n  <br>\n  <a href=\"https://click.linksynergy.com/link?id=D*o7yui4/NM&offerid=507388.922484&type=2&murl=https%3A%2F%2Fwww.udemy.com%2Fcourse%2Fthe-complete-nodejs-developer-course-2%2F&u1=21vl3Skt2fz9CZkPcetSToKITTB1Zqdi0ZpnMwjAMqG7p2N3J2BC5\">The Complete Node.js Developer Course</a><br>Learn Node. js by building real-world applications with Node, Express, MongoDB, Jest, and more!\n</p>\n\n---\n\n## Install\n\n```sh\n$ npm install passport-google-oauth20\n```\n\n###### TypeScript support\n\n```sh\n$ npm install @types/passport-google-oauth20\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\n`accessToken`, `refreshToken`, and `profile` as arguments.  `accessToken` and\n`refreshToken` are used for API access, and are not needed for authentication.\n`profile` contains the user's [profile information](https://www.passportjs.org/reference/normalized-profile/)\nstored in their Google account.  When authenticating a user, this strategy uses\nthe OAuth 2.0 protocol to obtain this information via a sequence of redirects\nand 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```javascript\nvar GoogleStrategy = require('passport-google-oauth20');\n\npassport.use(new GoogleStrategy({\n    clientID: GOOGLE_CLIENT_ID,\n    clientSecret: GOOGLE_CLIENT_SECRET,\n    callbackURL: 'https://www.example.com/oauth2/redirect/google',\n    scope: [ 'profile' ],\n    state: true\n  },\n  function verify(accessToken, refreshToken, profile, cb) {\n    db.get('SELECT * FROM federated_credentials WHERE provider = ? AND subject = ?', [\n      'https://accounts.google.com',\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            'https://accounts.google.com',\n            profile.id\n          ], function(err) {\n            if (err) { return cb(err); }\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, row) {\n          if (err) { return cb(err); }\n          if (!row) { return cb(null, false); }\n          return cb(null, row);\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-oauth2](https://github.com/passport/todos-express-google-oauth2)\n\n  Illustrates how to use the Google strategy within an Express application.\n\n## License\n\n[The MIT License](http://opensource.org/licenses/MIT)\n\nCopyright (c) 2012-2022 Jared Hanson <[https://www.jaredhanson.me/](https://www.jaredhanson.me/)>\n","readmeFilename":"README.md"}