StandardId Google Provider

This gem extracts the Google OAuth provider from the core standard_id engine so installations can opt into Google login independently of the base gem.

Installation

Add the gem next to standard_id:

# Gemfile
gem "standard_id"
gem "standard_id-google"

Then run:

bundle install

The gem automatically registers itself with StandardId when it is required.

Then run the install generator to drop the credentials block in place:

bin/rails g standard_id:google:install

This writes config/initializers/standard_id_google.rb — deliberately a separate file from config/initializers/standard_id.rb, so the provider can be removed by deleting one file and standard_id's own install generator stays free to overwrite its initializer without clobbering these values. Initializers load alphabetically, so the base config is applied first. The generator is idempotent; re-running on an existing initializer skips with a clear message (pass --force to overwrite).

Configuration

The generator writes this for you; the block is documented here for hosts configuring by hand. Configure your Google credentials inside the StandardId configuration block:

# config/initializers/standard_id.rb
StandardId.configure do |config|
  config.social.google_client_id = ENV.fetch("GOOGLE_OAUTH_CLIENT_ID", nil)
  config.social.google_client_secret = ENV.fetch("GOOGLE_OAUTH_CLIENT_SECRET", nil)
end

With those values in place, StandardId routes such as /auth/callback/google continue to function using this provider gem.

Boot ordering (standard_id <= 0.32.0)

These fields are declared by this gem, not by standard_id, and until standard_id 0.33.0 they were declared from this gem's Railtie after_initialize — which runs after config/initializers. On standard_id 0.32.0 and earlier the block above therefore raised:

StandardId::ConfigurationError: Unknown field 'google_client_id' for scope 'social'

The workaround was to wrap the writes:

# Only needed on standard_id <= 0.32.0
Rails.application.config.after_initialize do
  StandardId.configure do |config|
    config.social.google_client_id = ENV.fetch("GOOGLE_OAUTH_CLIENT_ID", nil)
    config.social.google_client_secret = ENV.fetch("GOOGLE_OAUTH_CLIENT_SECRET", nil)
  end
end

standard_id >= 0.33.0 declares every loaded provider's fields before :load_config_initializers, so a plain initializer is correct. The wrapper is no longer needed and existing ones keep working unchanged.

Note this is about ordering, not just versions: the fields do not exist without this gem in your Gemfile, on any standard_id version. Configuring social.google_* with the plugin absent raises the same error, correctly.

Testing

Run the provider test suite with:

bundle exec rspec

Development

  1. bin/setup
  2. bundle exec rspec

To release a new version:

  1. Update the version in lib/standard_id/google/version.rb.
  2. Run bundle exec rake release to tag, push, and publish to RubyGems.

License

The gem is available as open source under the terms of the MIT License.