<commit_before>::ActionView::Base.send :include, Multiauth::ViewsHelper

module Multiauth
  class Engine < ::Rails::Engine
    paths.app.controllers = File.expand_path("../../../app/controllers", __FILE__)
    paths.app.views       = File.expand_path("../../../app/views", __FILE__)
    paths.config.routes   = File.expand_path("../routes.rb", __FILE__)


    initializer "multiauth" do |app|

      config_file = Rails.root+"config/auth_providers.yml"

      if File.exist?(config_file)
        providers = YAML::load(ERB.new(File.read(config_file)).result)
        if providers.blank?
          raise ArgumentError, "#{config_file} is invalid"
        elsif providers[Rails.env].nil?
          raise ArgumentError, "cannot find section for #{Rails.env} environment in #{config_file}"
        end

        Multiauth.providers = providers[Rails.env]

        require 'omniauth/openid'
        require 'openid/store/filesystem'

        app.config.middleware.use OmniAuth::Strategies::OpenID, OpenID::Store::Filesystem.new('/tmp') # FIXME: mongodb store

        Devise.omniauth :open_id
        Multiauth.providers.each do |provider, config|
          next if config["token"].blank?

          puts ">> Setting up #{provider} provider"
          Devise.omniauth provider.underscore.to_sym, config["id"], config["token"]
        end
      else
        $stderr.puts "Config file doesn't exist: #{config_file}"
      end
    end

    config.to_prepare do
      ApplicationController.send(:include, Multiauth::Helpers)
    end
  end
end<commit_msg>add openid strategy using devise<commit_after>::ActionView::Base.send :include, Multiauth::ViewsHelper

module Multiauth
  class Engine < ::Rails::Engine
    paths.app.controllers = File.expand_path("../../../app/controllers", __FILE__)
    paths.app.views       = File.expand_path("../../../app/views", __FILE__)
    paths.config.routes   = File.expand_path("../routes.rb", __FILE__)


    initializer "multiauth" do |app|

      config_file = Rails.root+"config/auth_providers.yml"

      if File.exist?(config_file)
        providers = YAML::load(ERB.new(File.read(config_file)).result)
        if providers.blank?
          raise ArgumentError, "#{config_file} is invalid"
        elsif providers[Rails.env].nil?
          raise ArgumentError, "cannot find section for #{Rails.env} environment in #{config_file}"
        end

        Multiauth.providers = providers[Rails.env]

        require 'omniauth/openid'
        require 'openid/store/filesystem'

        if !Devise.omniauth_configs.has_key?(:open_id)
          Devise.omniauth :open_id, OpenID::Store::Filesystem.new('/tmp')
        end

        Multiauth.providers.each do |provider, config|
          next if config["token"].blank?

          puts ">> Setting up #{provider} provider"
          Devise.omniauth provider.underscore.to_sym, config["id"], config["token"]
        end
      else
        $stderr.puts "Config file doesn't exist: #{config_file}"
      end
    end

    config.to_prepare do
      ApplicationController.send(:include, Multiauth::Helpers)
    end
  end
end
{'fraction_non_alphanumeric': 0.12880258899676375, 'fraction_numerical': 0.0, 'mean_word_length': 2.8685857321652066, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '883527', 'n_tokens_mistral': 950, 'n_tokens_neox': 921, 'n_words': 191}