# TODO: Fixed in https://github.com/rack/rack/pull/1610 for Rack 3ifdefined?(RUBY_ENGINE)&&RUBY_ENGINE=="jruby"require'delegate'endrequire'rack'require'singleton'require'logger'moduleOmniAuthclassError<StandardError;endmoduleStrategiesautoload:Developer,'omniauth/strategies/developer'endautoload:Builder,'omniauth/builder'autoload:Strategy,'omniauth/strategy'autoload:Test,'omniauth/test'autoload:Form,'omniauth/form'autoload:AuthHash,'omniauth/auth_hash'autoload:FailureEndpoint,'omniauth/failure_endpoint'autoload:AuthenticityTokenProtection,'omniauth/authenticity_token_protection'defself.strategies@strategies||=[]endclassConfigurationincludeSingletondefself.default_loggerlogger=Logger.new(STDOUT)logger.progname='omniauth'loggerenddefself.defaults# rubocop:disable MethodLength@defaults||={:camelizations=>{},:path_prefix=>'/auth',:on_failure=>OmniAuth::FailureEndpoint,:failure_raise_out_environments=>['development'],:request_validation_phase=>OmniAuth::AuthenticityTokenProtection,:before_request_phase=>nil,:before_callback_phase=>nil,:before_options_phase=>nil,:form_css=>Form::DEFAULT_CSS,:test_mode=>false,:logger=>default_logger,:allowed_request_methods=>%i[post],:mock_auth=>{:default=>AuthHash.new('provider'=>'default','uid'=>'1234','info'=>{'name'=>'Example User'})},:silence_get_warning=>false}enddefinitializeself.class.defaults.each_pair{|k,v|send("#{k}=",v)}enddefon_failure(&block)ifblock_given?@on_failure=blockelse@on_failureendenddefbefore_callback_phase(&block)ifblock_given?@before_callback_phase=blockelse@before_callback_phaseendenddefbefore_options_phase(&block)ifblock_given?@before_options_phase=blockelse@before_options_phaseendenddefrequest_validation_phase(&block)ifblock_given?@request_validation_phase=blockelse@request_validation_phaseendenddefbefore_request_phase(&block)ifblock_given?@before_request_phase=blockelse@before_request_phaseendenddefadd_mock(provider,original={})# Create key-stringified new hash from given auth hashmock={}original.each_pairdo|key,val|mock[key.to_s]=ifval.is_a?HashHash[val.each_pair{|k,v|[k.to_s,v]}]elsevalendend# Merge with the default mock and ensure provider is correct.mock=mock_auth[:default].dup.merge(mock)mock['provider']=provider.to_s# Add it to the mocks.mock_auth[provider.to_sym]=mockend# This is a convenience method to be used by strategy authors# so that they can add special cases to the camelization utility# method that allows OmniAuth::Builder to work.## @param name [String] The underscored name, e.g. `oauth`# @param camelized [String] The properly camelized name, e.g. 'OAuth'defadd_camelization(name,camelized)camelizations[name.to_s]=camelized.to_sendattr_writer:on_failure,:before_callback_phase,:before_options_phase,:before_request_phase,:request_validation_phaseattr_accessor:failure_raise_out_environments,:path_prefix,:allowed_request_methods,:form_css,:test_mode,:mock_auth,:full_host,:camelizations,:logger,:silence_get_warningenddefself.configConfiguration.instanceenddefself.configureyieldconfigenddefself.loggerconfig.loggerenddefself.mock_auth_for(provider)config.mock_auth[provider.to_sym]||config.mock_auth[:default]endmoduleUtilsmodule_function# rubocop:disable Layout/IndentationWidthdefform_css"<style type='text/css'>#{OmniAuth.config.form_css}</style>"enddefdeep_merge(hash,other_hash)target=hash.dupother_hash.each_keydo|key|ifother_hash[key].is_a?(::Hash)&&hash[key].is_a?(::Hash)target[key]=deep_merge(target[key],other_hash[key])nextendtarget[key]=other_hash[key]endtargetenddefcamelize(word,first_letter_in_uppercase=true)returnOmniAuth.config.camelizations[word.to_s]ifOmniAuth.config.camelizations[word.to_s]iffirst_letter_in_uppercaseword.to_s.gsub(%r{/(.?)}){'::'+Regexp.last_match[1].upcase}.gsub(/(^|_)(.)/){Regexp.last_match[2].upcase}elsecamelize(word).tap{|w|w[0]=w[0].downcase}endendendend