Skip to content

Upgrade notes related with custom omniauth providers.#5760

Merged
tramuntanal merged 4 commits into0.21-stablefrom
doc/upgrade_notes_for_custom_oauth_methods_changes
Apr 30, 2020
Merged

Upgrade notes related with custom omniauth providers.#5760
tramuntanal merged 4 commits into0.21-stablefrom
doc/upgrade_notes_for_custom_oauth_methods_changes

Conversation

@tramuntanal
Copy link
Copy Markdown
Contributor

🎩 What? Why?

Thanks to #5516 it is now possible to customize which omniauth providers are enabled on each of the organizations in a multitenant installation.

But this also changes how this providers are configured in each installation.

This PR adds Upgrade notes to make developers/sysadmins aware of the required configuration change.

📌 Related Issues

📋 Subtasks

  • Add CHANGELOG entry
  • Add documentation regarding the feature
  • Add/modify seeds
  • Add tests
  • Another subtask

@tramuntanal tramuntanal self-assigned this Feb 19, 2020
Copy link
Copy Markdown
Contributor

@microstudi microstudi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@microstudi
Copy link
Copy Markdown
Contributor

However, I've been testing meta.decidim.org and I think the problem is not completely solved.
Here is the button of the omniauth against decidim.barcelona
image

However, it doesn't work anymore, probably due the configuration no longer has the line

Decidim::User.omniauth_providers << :decidim

But, if we have this line we duplicate the provider definition and the error is back.
So, either we force everyone to configure any omniauth via system (this breaks compatibility with current installations) or refactor somehow the code to not overwrite already defined providers by config, maybe it is possible to just reconfigure already defined providers (I guess we should look at the omniauth gem internals).

@tramuntanal
Copy link
Copy Markdown
Contributor Author

Hi @microstudi ,
We must clarify meta.decdim.org configuration with @decidim/product . It is working for edu.decidim.org which is in the same tenant.

@microstudi
Copy link
Copy Markdown
Contributor

yes they both need to be configured via system admin.
However, I think that an existing configuration should be used as a fallback if system is not configured. unless is too difficult, in which case we should explain in the release that custom providers have to be configured exclusively via system admin

@tramuntanal
Copy link
Copy Markdown
Contributor Author

@microstudi I don't think a default configuration should be used because in a given installation there may be organizations that don't want to have some, or any, of the configured custom OAuth providers.

@andreslucena andreslucena changed the title Upgrade notes related with cusom omniauth providers. Upgrade notes related with custom omniauth providers. Feb 24, 2020
Copy link
Copy Markdown
Contributor

@microstudi microstudi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am testing this but it's a little bit difficult to test it in localhost.

What I've found is not possible to just expect that omniauth providers won't need extra configuration options. Currenlty we handle cases for facebook, google and twitter (file decidim-core/config/initializers/omniauth.rb).

So, and initializizer file would be needed in most cases, for instance, for using Decidim as a provider we will need this code:

config/initializers/omniauth_decidim.rb:

if Rails.application.secrets.dig(:omniauth, :decidim).present?
  Rails.application.config.middleware.use OmniAuth::Builder do
    provider(
      :decidim,
      setup: ->(env) {
          request = Rack::Request.new(env)
          organization = Decidim::Organization.find_by(host: request.host)
          provider_config = organization.enabled_omniauth_providers[:decidim]

          env["omniauth.strategy"].options[:client_id] = provider_config[:client_id]
          env["omniauth.strategy"].options[:client_secret] = provider_config[:client_secret]
          env["omniauth.strategy"].options[:site] = provider_config[:site_url]
        },
      scope: :public
    )
  end
end

It would be also possible to add the specific case for the Decidim provider in the file decidim-core/config/initializers/omniauth.rb, in which case no initializer would be needed.

In this case the code needed should be:

    if omniauth_config[:google_oauth2].present?
      provider(
        :google_oauth2,
        setup: setup_provider_proc(:google_oauth2, client_id: :client_id, client_secret: :client_secret)
      )
    end

    if omniauth_config[:decidim].present?
      provider(
        :decidim,
        setup: setup_provider_proc(:decidim, client_id: :client_id, client_secret: :client_secret, site: :site_url),
        scope: :public
      )
    end
  end

CHANGELOG.md Outdated
Comment on lines +19 to +61
To make it clear, installations with custom Omniauth providers must remove the provider configuration from the corresponding `config/initializer/omniauth_xxx.rb`:

```
# This block should be kept
if Rails.application.secrets.dig(:omniauth, :decidim, :enabled)
Devise.setup do |config|
config.omniauth :decidim,
Rails.application.secrets.dig(:omniauth, :decidim, :client_id),
Rails.application.secrets.dig(:omniauth, :decidim, :client_secret),
Rails.application.secrets.dig(:omniauth, :decidim, :site_url),
scope: :public
end
end

# this line should be removed
Decidim::User.omniauth_providers << :decidim
```

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the new system, the whole initializer file is unnecessary. The only thing needed is the declaration in the secrets.yml file.

@tramuntanal tramuntanal changed the base branch from release/0.21.0 to master April 22, 2020 16:04
@tramuntanal tramuntanal force-pushed the doc/upgrade_notes_for_custom_oauth_methods_changes branch from b565c9e to 9d92828 Compare April 22, 2020 16:17
@tramuntanal tramuntanal changed the base branch from master to develop April 29, 2020 11:10
@tramuntanal tramuntanal changed the base branch from develop to master April 29, 2020 11:13
@jesusdb jesusdb self-requested a review April 30, 2020 14:09
@tramuntanal tramuntanal changed the base branch from master to 0.21-stable April 30, 2020 14:21
@tramuntanal tramuntanal merged commit a9715ed into 0.21-stable Apr 30, 2020
@tramuntanal tramuntanal deleted the doc/upgrade_notes_for_custom_oauth_methods_changes branch April 30, 2020 14:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants