{"id":13631725,"url":"https://github.com/basecamp/google_sign_in","last_synced_at":"2025-10-08T18:09:05.811Z","repository":{"id":21471124,"uuid":"92837461","full_name":"basecamp/google_sign_in","owner":"basecamp","description":"Sign in (or up) with Google for Rails applications","archived":false,"fork":false,"pushed_at":"2024-07-03T16:22:06.000Z","size":109,"stargazers_count":528,"open_issues_count":5,"forks_count":54,"subscribers_count":23,"default_branch":"master","last_synced_at":"2025-04-02T23:49:50.777Z","etag":null,"topics":["google","ruby-on-rails"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":false,"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/basecamp.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-30T13:46:32.000Z","updated_at":"2025-03-19T03:33:53.000Z","dependencies_parsed_at":"2024-08-01T22:40:07.399Z","dependency_job_id":null,"html_url":"https://github.com/basecamp/google_sign_in","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basecamp%2Fgoogle_sign_in","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basecamp%2Fgoogle_sign_in/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basecamp%2Fgoogle_sign_in/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/basecamp%2Fgoogle_sign_in/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/basecamp","download_url":"https://codeload.github.com/basecamp/google_sign_in/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248389570,"owners_count":21095616,"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","ruby-on-rails"],"created_at":"2024-08-01T22:02:35.959Z","updated_at":"2025-10-08T18:09:05.803Z","avatar_url":"https://github.com/basecamp.png","language":"Ruby","funding_links":[],"categories":["Ruby","Uncategorized"],"sub_categories":["Uncategorized"],"readme":"# Google Sign-In for Rails\n\nThis gem allows you to add Google sign-in to your Rails app. You can let users sign up for and sign in to your service\nwith their Google accounts.\n\n\n## Installation\n\nAdd `google_sign_in` to your Rails app’s Gemfile and run `bundle install`:\n\n```ruby\ngem 'google_sign_in'\n```\n\nGoogle Sign-In for Rails requires Rails 5.2 or newer.\n\n\n## Configuration\n\nFirst, set up an OAuth 2.0 Client ID in the Google API Console:\n\n1. Go to the [API Console](https://console.developers.google.com/apis/credentials).\n\n2. In the projects menu at the top of the page, ensure the correct project is selected or create a new one.\n\n3. In the left-side navigation menu, choose APIs \u0026 Services → Credentials.\n\n4. Click the button labeled “Create credentials.” In the menu that appears, choose to create an **OAuth client ID**.\n\n5. When prompted to select an application type, select **Web application**.\n\n6. Enter your application’s name.\n\n7. This gem adds a single OAuth callback to your app at `/google_sign_in/callback`. Under **Authorized redirect URIs**,\n   add that callback for your application’s domain: for example, `https://example.com/google_sign_in/callback`.\n\n   To use Google sign-in in development, you’ll need to add another redirect URI for your local environment, like\n   `http://localhost:3000/google_sign_in/callback`. For security reasons, we recommend using a separate\n   client ID for local development. Repeat these instructions to set up a new client ID for development.\n\n8. Click the button labeled “Create.” You’ll be presented with a client ID and client secret. Save these.\n\nWith your client ID set up, configure your Rails application to use it. Run `bin/rails credentials:edit` to edit your\napp’s [encrypted credentials](https://guides.rubyonrails.org/security.html#custom-credentials) and add the following:\n\n```yaml\ngoogle_sign_in:\n  client_id: [Your client ID here]\n  client_secret: [Your client secret here]\n```\n\nYou’re all set to use Google sign-in now. The gem automatically uses the client ID and client secret in your credentials.\n\nAlternatively, you can provide the client ID and client secret using ENV variables. Add a new initializer that sets\n`config.google_sign_in.client_id` and `config.google_sign_in.client_secret`:\n\n```ruby\n# config/initializers/google_sign_in.rb\nRails.application.configure do\n  config.google_sign_in.client_id     = ENV['google_sign_in_client_id']\n  config.google_sign_in.client_secret = ENV['google_sign_in_client_secret']\nend\n```\n\n**⚠️ Important:** Take care to protect your client secret from disclosure to third parties.\n\n9. (Optional) The callback route can be configured using:\n\n```ruby\n# config/initializers/google_sign_in.rb\nRails.application.configure do\n  config.google_sign_in.root = \"my_own/google_sign_in_route\"\nend\n```\n\nWhich would make the callback `/my_own/google_sign_in_route/callback`.\n\n## Usage\n\nThis gem provides a `google_sign_in_button` helper to generate a button that initiates Google sign-in:\n\n```erb\n\u003c%= google_sign_in_button 'Sign in with my Google account', proceed_to: create_login_url %\u003e\n\n\u003c%= google_sign_in_button image_tag('google_logo.png', alt: 'Google'), proceed_to: create_login_url %\u003e\n\n\u003c%= google_sign_in_button proceed_to: create_login_url do %\u003e\n  Sign in with my \u003c%= image_tag('google_logo.png', alt: 'Google') %\u003e account\n\u003c% end %\u003e\n```\n\nWhen using with Hotwire and Turbo, add the \"turbo=false\" HTML data attribute to the button to\nprevent Turbo from executing it asynchonously. For example:\n\n```erb\n\u003c%= google_sign_in_button 'Sign in with my Google account',\n      proceed_to: create_login_url,\n      data: { turbo: \"false\" } %\u003e\n```\n\nThe `proceed_to` argument is required. After authenticating with Google, the gem redirects to `proceed_to`, providing\na Google ID token in `flash[:google_sign_in][:id_token]` or an [OAuth authorizaton code grant error](https://tools.ietf.org/html/rfc6749#section-4.1.2.1)\nin `flash[:google_sign_in][:error]`. Your application decides what to do with it:\n\n```ruby\n# config/routes.rb\nRails.application.routes.draw do\n  # ...\n  get 'login', to: 'logins#new'\n  get 'login/create', to: 'logins#create', as: :create_login\nend\n```\n\n```ruby\n# app/controllers/logins_controller.rb\nclass LoginsController \u003c ApplicationController\n  def new\n  end\n\n  def create\n    if user = authenticate_with_google\n      cookies.signed[:user_id] = user.id\n      redirect_to user\n    else\n      redirect_to new_session_url, alert: 'authentication_failed'\n    end\n  end\n\n  private\n    def authenticate_with_google\n      if id_token = flash[:google_sign_in][:id_token]\n        User.find_by google_id: GoogleSignIn::Identity.new(id_token).user_id\n      elsif error = flash[:google_sign_in][:error]\n        logger.error \"Google authentication error: #{error}\"\n        nil\n      end\n    end\nend\n```\n\n(The above example assumes the user has already signed up for your service and that you’re storing their Google user ID\nin the `User#google_id` attribute.)\n\nFor security reasons, the `proceed_to` URL you provide to `google_sign_in_button` is required to reside on the same\norigin as your application. This means it must have the same protocol, host, and port as the page where\n`google_sign_in_button` is used. We enforce this before redirecting to the `proceed_to` URL to guard against\n[open redirects](https://www.owasp.org/index.php/Unvalidated_Redirects_and_Forwards_Cheat_Sheet).\n\n### `GoogleSignIn::Identity`\n\nThe `GoogleSignIn::Identity` class decodes and verifies the integrity of a Google ID token. It exposes the profile\ninformation contained in the token via the following instance methods:\n\n* `name`\n\n* `email_address`\n\n* `user_id`: A string that uniquely identifies a single Google user. Use this, not `email_address`, to associate a\n  Google user with an application user. A Google user’s email address may change, but their `user_id` will remain constant.\n\n* `email_verified?`\n\n* `avatar_url`\n\n* `locale`\n\n* `hosted_domain`: The user’s hosted G Suite domain, provided only if they belong to a G Suite.\n\n* `given_name`: The user's given name.\n\n* `family_name`: The user's last name.\n\n\n## Security\n\nFor information on our security response procedure, see [SECURITY.md](SECURITY.md).\n\n## Maintenance\n\nShort of patching critical security issues, this gem is now considered done, and will not see any further feature development or minor bug fixes. Feel free to fork this work under the MIT license and continue the feature development under a different name.\n\n## Development\n\nTo set up dependencies locally:\n\n``` sh\nbin/setup\n```\n\nTo run the tests against multiple versions of Rails:\n\n``` sh\nbin/test\n```\n\n## License\n\nGoogle Sign-In for Rails is released under the [MIT License](https://opensource.org/licenses/MIT).\n\nGoogle is a registered trademark of Google LLC. This project is not operated by or in any way affiliated with Google LLC.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasecamp%2Fgoogle_sign_in","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbasecamp%2Fgoogle_sign_in","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasecamp%2Fgoogle_sign_in/lists"}