{"id":17033485,"url":"https://github.com/morgul/passport-google-web","last_synced_at":"2025-10-11T15:13:22.383Z","repository":{"id":57320085,"uuid":"65687138","full_name":"Morgul/passport-google-web","owner":"Morgul","description":"A simple implementation of 'Google Sign-In for Websites'.","archived":false,"fork":false,"pushed_at":"2022-02-27T18:26:17.000Z","size":8,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-15T10:27:34.099Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/Morgul.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":"2016-08-14T21:27:13.000Z","updated_at":"2022-06-04T16:58:56.000Z","dependencies_parsed_at":"2022-08-25T21:01:01.483Z","dependency_job_id":null,"html_url":"https://github.com/Morgul/passport-google-web","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/Morgul/passport-google-web","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morgul%2Fpassport-google-web","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morgul%2Fpassport-google-web/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morgul%2Fpassport-google-web/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morgul%2Fpassport-google-web/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Morgul","download_url":"https://codeload.github.com/Morgul/passport-google-web/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Morgul%2Fpassport-google-web/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279007599,"owners_count":26084333,"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","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-14T08:34:59.030Z","updated_at":"2025-10-11T15:13:22.369Z","avatar_url":"https://github.com/Morgul.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Passport Strategy for \"Google Sign-In for Websites\"\n\nThis is a very simple implementation of the backend portion of the [\"Google Sign-In for Websites\"][google-signin]\nauthentication flow. It's very easy to set up and the code is very simple. It also has no dependencies, other than\npassport itself.\n\n[google-signin]: \"https://developers.google.com/identity/sign-in/web/\"\n\n## Usage\n\n### Create a Google API Console project\n\nBefore using `passport-google-web`, you will need to create a [Google API Console][create-project] project. In the\nproject, you create a client ID, which you will need to call the sign-in API.\n\n[create-project]: https://developers.google.com/identity/sign-in/web/devconsole-project\n\n### Configure the client side\n\n#### Load the Google Platform Library\n\nYou must include the Google Platform Library on your web pages that integrate Google Sign-In.\n\n```javascript\n\u003cscript src=\"https://apis.google.com/js/platform.js\" async defer\u003e\u003c/script\u003e\n```\n\n#### Specify your app's client ID\n\nSpecify the client ID you created for your app in the Google Developers Console with the `google-signin-client_id` meta\nelement.\n\n```html\n\u003cmeta name=\"google-signin-client_id\" content=\"YOUR_CLIENT_ID.apps.googleusercontent.com\"\u003e\n```\n\n#### Add a Google Sign-In button\n\nThe easiest way to add a Google Sign-In button to your site is to use an automatically rendered sign-in button. With\nonly a few lines of code, you can add a button that automatically configures itself to have the appropriate text, logo,\nand colors for the sign-in state of the user and the scopes you request.\n\n```html\n\u003cdiv class=\"g-signin2\" data-onsuccess=\"onSignIn\"\u003e\u003c/div\u003e\n```\n\n#### Send the ID token to your server\n\nAfter a user successfully signs in, get the user's ID token:\n\n```javascript\nfunction onSignIn(googleUser) {\n  var id_token = googleUser.getAuthResponse().id_token;\n  ...\n}\n```\n\nThen, send the ID token to your server with an HTTPS POST request:\n\n```javascript\nvar xhr = new XMLHttpRequest();\nxhr.open('POST', 'https://yourbackend.example.com/tokensignin');\nxhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');\nxhr.onload = function() {\n  console.log('Signed in as: ' + xhr.responseText);\n};\nxhr.send('idToken=' + idToken);\n```\n\n#### Example\n\nHere is an example of the client setup:\n\n```html\n\n\u003chtml lang=\"en\"\u003e\n\t\u003chead\u003e\n\t\t\u003cmeta name=\"google-signin-scope\" content=\"profile email\"\u003e\n\t\t\u003cmeta name=\"google-signin-client_id\" content=\"YOUR_CLIENT_ID.apps.googleusercontent.com\"\u003e\n\t\t\u003cscript src=\"https://apis.google.com/js/platform.js\" async defer\u003e\u003c/script\u003e\n\t\u003c/head\u003e\n\t\u003cbody\u003e\n\t\t\u003c!-- The sign-in button --\u003e\n\t\t\u003cdiv class=\"g-signin2\" data-onsuccess=\"onSignIn\" data-theme=\"dark\"\u003e\u003c/div\u003e\n\t\t\u003c!-- Sign-in script --\u003e\n\t\t\u003cscript\u003e\n\t\t\tfunction onSignIn(googleUser)\n\t\t\t{\n\t\t\t\t// Retrieve the id_token\n\t\t\t\tconst idToken = googleUser.getAuthResponse().id_token;\n\n\t\t\t\t// Send it as a post to the backend server\n\t\t\t\tconst xhr = new XMLHttpRequest();\n\t\t\t\txhr.open('POST', 'https://yourbackend.example.com/tokensignin');\n\t\t\t\txhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');\n\t\t\t\txhr.onload = function ()\n\t\t\t\t{\n\t\t\t\t\tconsole.log('Signed in as: ' + xhr.responseText);\n\t\t\t\t};\n\t\t\t\txhr.send('idToken=' + idToken);\n\t\t\t}\n\t\t\u003c/script\u003e\n\t\u003c/body\u003e\n\u003c/html\u003e\n```\n\n### Configure Strategy\n\nThe `passport-google-web` strategy uses a simplified OAuth 2.0 flow, designed to be very easy to implement. Once the\nclient side callback sends the `idToken` to the backend, the authentication is already complete. All that is required is\nfor the backend to validate the token, to ensure it's not being forged. As such, there's every little required of the\nstrategy, and no configuration options required.\n\n```javascript\nvar GoogleStrategy = require('passport-google-web');\n\npassport.use(new GoogleStrategy(function(token, profile, done) {\n    User.findOrCreate({ googleId: profile.id }, function(err, user) {\n      return cb(err, user);\n    });\n  }\n));\n```\n\n### Authenticate Requests\n\nUse `passport.authenticate()`, specifying the `google-signin` strategy, to authenticate requests.\n\nFor example, as route middleware in an [Express](http://expressjs.com) application:\n\n```javascript\napp.post('/auth/google', passport.authenticate('google-signin'), function(req, resp)\n{\n\tresp.json(req.user);\n});\n```\n\n## License\n\n[The MIT License](http://opensource.org/licenses/MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorgul%2Fpassport-google-web","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmorgul%2Fpassport-google-web","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorgul%2Fpassport-google-web/lists"}