<commit_before>require 'faraday'
require 'faraday_middleware'

require 'log4r'


configure do

  def logger
    Log4r::Logger['test']    
  end

  
  set :logging, Logger::INFO

  # Work around rack protection referrer bug
  set :protection, :except => :json_csrf
  
  # Configure template engine for partials
  set :partial_template_engine, :erb

  # Configure API connection to remote service
  logger.info "Configuring remote search API, connecting to " + settings.server_url
  server = Faraday.new(:url => settings.server_url) do |c|
    logger.debug c.ai
    c.use FaradayMiddleware::FollowRedirects, :limit => 5
    c.adapter :net_http
    c.headers = {'Accept' => "application/xml"}
  end
  set :server, server
  
  # Configure Mongo for local storage
  logger.info "Configuring Mongo: url=" + settings.mongo_host  
  set :mongo, Mongo::Connection.new(settings.mongo_host)
  set :works, settings.mongo[settings.mongo_db]['works']
  set :bios, settings.mongo[settings.mongo_db]['bios']
  set :claims, settings.mongo[settings.mongo_db]['claims']
  set :orcids, settings.mongo[settings.mongo_db]['orcids']

  # Set facet fields
  set :facet_fields, ['type', 'something else']


  # Google analytics event tracking
  set :ga, Gabba::Gabba.new(settings.gabba[:cookie], settings.gabba[:url]) if settings.gabba[:cookie]

  # Orcid endpoint
  logger.info "Configuring ORCID, client app ID #{settings.orcid[:client_id]} connecting to #{settings.orcid[:site]}"
  set :orcid_service, Faraday.new(:url => settings.orcid[:site])

  # Orcid oauth2 object we can use to make API calls
  set :orcid_oauth, OAuth2::Client.new(settings.orcid[:client_id],
                                       settings.orcid[:client_secret],
                                       {:site => settings.orcid[:site]})

  # Set up session and auth middlewares for ORCID sign in
  use Rack::Session::Mongo, settings.mongo[settings.mongo_db]
  use Rack::Flash
  use OmniAuth::Builder do
    provider :orcid, settings.orcid[:client_id], settings.orcid[:client_secret],
    :authorize_params => {
      # ToDo move the scope params to config file?
      #:scope => '/orcid-profile/read-limited /orcid-bio/external-identifiers/create'
      :scope => '/orcid-bio/external-identifiers/create'
    },
    :client_options => {
      :site => settings.orcid[:site],
      :authorize_url => settings.orcid[:authorize_url],
      :token_url => settings.orcid[:token_url],
    }
  end
  OmniAuth.config.logger = logger

  set :show_exceptions, true
end

<commit_msg>Set OmniAuth provider option provider_ignores_state to true. This makes OAuth links to the app from other sites work without the `state` parameter, including the import wizard links on orcid.org.<commit_after>require 'faraday'
require 'faraday_middleware'

require 'log4r'


configure do

  def logger
    Log4r::Logger['test']    
  end

  
  set :logging, Logger::INFO

  # Work around rack protection referrer bug
  set :protection, :except => :json_csrf
  
  # Configure template engine for partials
  set :partial_template_engine, :erb

  # Configure API connection to remote service
  logger.info "Configuring remote search API, connecting to " + settings.server_url
  server = Faraday.new(:url => settings.server_url) do |c|
    logger.debug c.ai
    c.use FaradayMiddleware::FollowRedirects, :limit => 5
    c.adapter :net_http
    c.headers = {'Accept' => "application/xml"}
  end
  set :server, server
  
  # Configure Mongo for local storage
  logger.info "Configuring Mongo: url=" + settings.mongo_host  
  set :mongo, Mongo::Connection.new(settings.mongo_host)
  set :works, settings.mongo[settings.mongo_db]['works']
  set :bios, settings.mongo[settings.mongo_db]['bios']
  set :claims, settings.mongo[settings.mongo_db]['claims']
  set :orcids, settings.mongo[settings.mongo_db]['orcids']

  # Set facet fields
  set :facet_fields, ['type', 'something else']


  # Google analytics event tracking
  set :ga, Gabba::Gabba.new(settings.gabba[:cookie], settings.gabba[:url]) if settings.gabba[:cookie]

  # Orcid endpoint
  logger.info "Configuring ORCID, client app ID #{settings.orcid[:client_id]} connecting to #{settings.orcid[:site]}"
  set :orcid_service, Faraday.new(:url => settings.orcid[:site])

  # Orcid oauth2 object we can use to make API calls
  set :orcid_oauth, OAuth2::Client.new(settings.orcid[:client_id],
                                       settings.orcid[:client_secret],
                                       {:site => settings.orcid[:site]})

  # Set up session and auth middlewares for ORCID sign in
  use Rack::Session::Mongo, settings.mongo[settings.mongo_db]
  use Rack::Flash
  use OmniAuth::Builder do
    provider :orcid, settings.orcid[:client_id], settings.orcid[:client_secret],
    :authorize_params => {
      # ToDo move the scope params to config file?
      #:scope => '/orcid-profile/read-limited /orcid-bio/external-identifiers/create'
      :scope => '/orcid-bio/external-identifiers/create'
    },
    :client_options => {
      :site => settings.orcid[:site],
      :authorize_url => settings.orcid[:authorize_url],
      :token_url => settings.orcid[:token_url],
    },
    :provider_ignores_state => true
  end
  OmniAuth.config.logger = logger

  set :show_exceptions, true
end


{'fraction_non_alphanumeric': 0.11927825261158595, 'fraction_numerical': 0.001899335232668566, 'mean_word_length': 3.7313566936208447, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5583821', 'n_tokens_mistral': 1714, 'n_tokens_neox': 1654, 'n_words': 414}