<commit_before>require 'omniauth/strategies/noosfero_oauth2'

class OauthClientPlugin < Noosfero::Plugin

  def self.plugin_name
    "Oauth Client Plugin"
  end

  def self.plugin_description
    _("Login with Oauth.")
  end

  def login_extra_contents
    plugin = self
    proc do
      render :partial => 'auth/oauth_login', :locals => {:providers => environment.oauth_providers.enabled}
    end
  end

  def signup_extra_contents
    plugin = self

    proc do
      if plugin.context.session[:oauth_data].present?
        render :partial => 'account/oauth_signup'
      else
        ''
      end
    end
  end

  PROVIDERS = {
    :facebook => {
      :name => 'Facebook'
    },
    :google_oauth2 => {
      :name => 'Google'
    },
    :noosfero_oauth2 => {
      :name => 'Noosfero'
    }
  }

  def stylesheet?
    true
  end

  OmniAuth.config.on_failure = OauthClientPluginPublicController.action(:failure)

  Rails.application.config.middleware.use OmniAuth::Builder do
    PROVIDERS.each do |provider, options|
      setup = lambda { |env|
        request = Rack::Request.new env
        strategy = env['omniauth.strategy']

        domain = Domain.find_by_name(request.host)
        environment = domain.environment rescue Environment.default

        provider_id = request.session['omniauth.params'] ? request.session['omniauth.params']['id'] : request.params['id']
        provider = environment.oauth_providers.find(provider_id)
        strategy.options.merge!(provider.options.symbolize_keys)

        request.session[:provider_id] = provider_id
      }

      provider provider, :setup => setup,
        :path_prefix => '/plugin/oauth_client',
        :callback_path => "/plugin/oauth_client/public/callback/#{provider}",
        :client_options => { :connection_opts => { :proxy => ENV["OAUTH_HTTP_PROXY"] } }<commit_msg>oauth_client: fix oauth login flow<commit_after>require 'omniauth/strategies/noosfero_oauth2'

class OauthClientPlugin < Noosfero::Plugin

  def self.plugin_name
    "Oauth Client Plugin"
  end

  def self.plugin_description
    _("Login with Oauth.")
  end

  def login_extra_contents
    plugin = self
    proc do
      render :partial => 'auth/oauth_login', :locals => {:providers => environment.oauth_providers.enabled}
    end
  end

  def signup_extra_contents
    plugin = self

    proc do
      if plugin.context.session[:oauth_data].present?
        render :partial => 'account/oauth_signup'
      else
        ''
      end
    end
  end

  PROVIDERS = {
    :facebook => {
      :name => 'Facebook'
    },
    :google_oauth2 => {
      :name => 'Google'
    },
    :noosfero_oauth2 => {
      :name => 'Noosfero'
    }
  }

  def stylesheet?
    true
  end

  OmniAuth.config.on_failure = OauthClientPluginPublicController.action(:failure)

  Rails.application.config.middleware.use OmniAuth::Builder do
    PROVIDERS.each do |provider, options|
      setup = lambda { |env|
        request = Rack::Request.new env
        strategy = env['omniauth.strategy']

        domain = Domain.find_by_name(request.host)
        environment = domain.environment rescue Environment.default

        provider_id = request.params['id']
        provider_id ||= request.session['omniauth.params']['id'] if request.session['omniauth.params']
        provider = environment.oauth_providers.find(provider_id)
        strategy.options.merge!(provider.options.symbolize_keys)

        request.session[:provider_id] = provider_id
      }

      provider provider, :setup => setup,
        :path_prefix => '/plugin/oauth_client',
        :callback_path => "/plugin/oauth_client/public/callback/#{provider}",
        :client_options => { :connection_opts => { :proxy => ENV["OAUTH_HTTP_PROXY"] } }
{'fraction_non_alphanumeric': 0.11540526033279656, 'fraction_numerical': 0.001610305958132045, 'mean_word_length': 2.956475583864119, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '246364', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1145, 'n_words': 214}