1
0
Fork 0
mirror of https://github.com/omniauth/omniauth.git synced 2022-11-09 12:31:49 -05:00

Added Content-Type to default failed login redirection.

This commit is contained in:
Sam Schenkman-Moore 2010-10-11 21:20:30 -04:00
parent 0eafa3d229
commit b03100454f

View file

@ -3,35 +3,35 @@ require 'singleton'
require 'omniauth/form' require 'omniauth/form'
module OmniAuth module OmniAuth
autoload :Builder, 'omniauth/builder' autoload :Builder, 'omniauth/builder'
autoload :Strategy, 'omniauth/strategy' autoload :Strategy, 'omniauth/strategy'
autoload :Test, 'omniauth/test' autoload :Test, 'omniauth/test'
module Strategies module Strategies
autoload :Password, 'omniauth/strategies/password' autoload :Password, 'omniauth/strategies/password'
end end
class Configuration class Configuration
include Singleton include Singleton
@@defaults = { @@defaults = {
:path_prefix => '/auth', :path_prefix => '/auth',
:on_failure => Proc.new do |env, message_key| :on_failure => Proc.new do |env, message_key|
new_path = "#{OmniAuth.config.path_prefix}/failure?message=#{message_key}" new_path = "#{OmniAuth.config.path_prefix}/failure?message=#{message_key}"
[302, {'Location' => "#{new_path}"}, []] [302, {'Location' => "#{new_path}", 'Content-Type'=> 'text/html'}, []]
end, end,
:form_css => Form::DEFAULT_CSS :form_css => Form::DEFAULT_CSS
} }
def self.defaults def self.defaults
@@defaults @@defaults
end end
def initialize def initialize
@@defaults.each_pair{|k,v| self.send("#{k}=",v)} @@defaults.each_pair{|k,v| self.send("#{k}=",v)}
end end
def on_failure(&block) def on_failure(&block)
if block_given? if block_given?
@on_failure = block @on_failure = block
@ -39,19 +39,19 @@ module OmniAuth
@on_failure @on_failure
end end
end end
attr_writer :on_failure attr_writer :on_failure
attr_accessor :path_prefix, :form_css attr_accessor :path_prefix, :form_css
end end
def self.config def self.config
Configuration.instance Configuration.instance
end end
def self.configure def self.configure
yield config yield config
end end
module Utils module Utils
CAMELIZE_SPECIAL = { CAMELIZE_SPECIAL = {
'oauth' => 'OAuth', 'oauth' => 'OAuth',
@ -60,31 +60,31 @@ module OmniAuth
'open_id' => 'OpenID', 'open_id' => 'OpenID',
'github' => 'GitHub' 'github' => 'GitHub'
} }
module_function module_function
def form_css def form_css
"<style type='text/css'>#{OmniAuth.config.form_css}</style>" "<style type='text/css'>#{OmniAuth.config.form_css}</style>"
end end
def deep_merge(hash, other_hash) def deep_merge(hash, other_hash)
target = hash.dup target = hash.dup
other_hash.keys.each do |key| other_hash.keys.each do |key|
if other_hash[key].is_a? ::Hash and hash[key].is_a? ::Hash if other_hash[key].is_a? ::Hash and hash[key].is_a? ::Hash
target[key] = deep_merge(target[key],other_hash[key]) target[key] = deep_merge(target[key],other_hash[key])
next next
end end
target[key] = other_hash[key] target[key] = other_hash[key]
end end
target target
end end
def camelize(word, first_letter_in_uppercase = true) def camelize(word, first_letter_in_uppercase = true)
return CAMELIZE_SPECIAL[word.to_s] if CAMELIZE_SPECIAL[word.to_s] return CAMELIZE_SPECIAL[word.to_s] if CAMELIZE_SPECIAL[word.to_s]
if first_letter_in_uppercase if first_letter_in_uppercase
word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase } word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
else else