omniauth 0.2.6 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +62 -34
- data/lib/omniauth/version.rb +2 -2
- metadata +59 -225
- data/.autotest +0 -9
- data/.document +0 -5
- data/.gemtest +0 -0
- data/.gitignore +0 -56
- data/.rspec +0 -2
- data/.travis.yml +0 -9
- data/.yardopts +0 -4
- data/Gemfile +0 -12
- data/Rakefile +0 -51
- data/oa-basic/.gemtest +0 -0
- data/oa-basic/.rspec +0 -3
- data/oa-basic/.yardopts +0 -4
- data/oa-basic/Gemfile +0 -7
- data/oa-basic/LICENSE +0 -19
- data/oa-basic/README.rdoc +0 -34
- data/oa-basic/Rakefile +0 -6
- data/oa-basic/lib/oa-basic.rb +0 -1
- data/oa-basic/lib/omniauth/basic.rb +0 -8
- data/oa-basic/lib/omniauth/strategies/http_basic.rb +0 -56
- data/oa-basic/lib/omniauth/version.rb +0 -19
- data/oa-basic/oa-basic.gemspec +0 -27
- data/oa-basic/spec/omniauth/strategies/basic_spec.rb +0 -7
- data/oa-basic/spec/spec_helper.rb +0 -11
- data/oa-core/.gemtest +0 -0
- data/oa-core/.rspec +0 -3
- data/oa-core/.yardopts +0 -4
- data/oa-core/Gemfile +0 -3
- data/oa-core/LICENSE +0 -19
- data/oa-core/Rakefile +0 -6
- data/oa-core/autotest/discover.rb +0 -1
- data/oa-core/lib/oa-core.rb +0 -1
- data/oa-core/lib/omniauth/builder.rb +0 -33
- data/oa-core/lib/omniauth/core.rb +0 -135
- data/oa-core/lib/omniauth/form.rb +0 -186
- data/oa-core/lib/omniauth/strategy.rb +0 -227
- data/oa-core/lib/omniauth/test/phony_session.rb +0 -8
- data/oa-core/lib/omniauth/test/strategy_macros.rb +0 -34
- data/oa-core/lib/omniauth/test/strategy_test_case.rb +0 -49
- data/oa-core/lib/omniauth/test.rb +0 -12
- data/oa-core/lib/omniauth/version.rb +0 -19
- data/oa-core/oa-core.gemspec +0 -24
- data/oa-core/spec/omniauth/builder_spec.rb +0 -20
- data/oa-core/spec/omniauth/core_spec.rb +0 -79
- data/oa-core/spec/omniauth/strategy_spec.rb +0 -363
- data/oa-core/spec/spec_helper.rb +0 -12
- data/oa-enterprise/.gemtest +0 -0
- data/oa-enterprise/.rspec +0 -3
- data/oa-enterprise/.yardopts +0 -4
- data/oa-enterprise/Gemfile +0 -7
- data/oa-enterprise/LICENSE +0 -19
- data/oa-enterprise/README.rdoc +0 -82
- data/oa-enterprise/Rakefile +0 -6
- data/oa-enterprise/lib/oa-enterprise.rb +0 -1
- data/oa-enterprise/lib/omniauth/enterprise.rb +0 -8
- data/oa-enterprise/lib/omniauth/strategies/cas/configuration.rb +0 -98
- data/oa-enterprise/lib/omniauth/strategies/cas/service_ticket_validator.rb +0 -91
- data/oa-enterprise/lib/omniauth/strategies/cas.rb +0 -47
- data/oa-enterprise/lib/omniauth/strategies/ldap/adaptor.rb +0 -279
- data/oa-enterprise/lib/omniauth/strategies/ldap.rb +0 -111
- data/oa-enterprise/lib/omniauth/version.rb +0 -19
- data/oa-enterprise/oa-enterprise.gemspec +0 -31
- data/oa-enterprise/spec/fixtures/cas_failure.xml +0 -4
- data/oa-enterprise/spec/fixtures/cas_success.xml +0 -8
- data/oa-enterprise/spec/omniauth/strategies/cas_spec.rb +0 -94
- data/oa-enterprise/spec/omniauth/strategies/ldap_spec.rb +0 -41
- data/oa-enterprise/spec/spec_helper.rb +0 -14
- data/oa-more/.gemtest +0 -0
- data/oa-more/.rspec +0 -3
- data/oa-more/.yardopts +0 -4
- data/oa-more/Gemfile +0 -7
- data/oa-more/LICENSE +0 -19
- data/oa-more/README.rdoc +0 -22
- data/oa-more/Rakefile +0 -6
- data/oa-more/lib/oa-more.rb +0 -1
- data/oa-more/lib/omniauth/more.rb +0 -11
- data/oa-more/lib/omniauth/strategies/draugiem.rb +0 -104
- data/oa-more/lib/omniauth/strategies/flickr.rb +0 -86
- data/oa-more/lib/omniauth/strategies/ign.rb +0 -93
- data/oa-more/lib/omniauth/strategies/windows_live/windowslivelogin.rb +0 -1143
- data/oa-more/lib/omniauth/strategies/windows_live.rb +0 -39
- data/oa-more/lib/omniauth/strategies/yupoo.rb +0 -67
- data/oa-more/lib/omniauth/version.rb +0 -19
- data/oa-more/oa-more.gemspec +0 -29
- data/oa-more/spec/omniauth/strategies/draugiem_spec.rb +0 -51
- data/oa-more/spec/omniauth/strategies/flickr_spec.rb +0 -7
- data/oa-more/spec/spec_helper.rb +0 -11
- data/oa-oauth/.gemtest +0 -0
- data/oa-oauth/.rspec +0 -3
- data/oa-oauth/.yardopts +0 -4
- data/oa-oauth/Gemfile +0 -7
- data/oa-oauth/LICENSE +0 -19
- data/oa-oauth/README.rdoc +0 -35
- data/oa-oauth/Rakefile +0 -6
- data/oa-oauth/autotest/discover.rb +0 -1
- data/oa-oauth/lib/oa-oauth.rb +0 -1
- data/oa-oauth/lib/omniauth/oauth.rb +0 -56
- data/oa-oauth/lib/omniauth/strategies/bitly.rb +0 -46
- data/oa-oauth/lib/omniauth/strategies/dailymile.rb +0 -64
- data/oa-oauth/lib/omniauth/strategies/doit.rb +0 -60
- data/oa-oauth/lib/omniauth/strategies/dopplr.rb +0 -53
- data/oa-oauth/lib/omniauth/strategies/douban.rb +0 -60
- data/oa-oauth/lib/omniauth/strategies/evernote.rb +0 -54
- data/oa-oauth/lib/omniauth/strategies/facebook.rb +0 -70
- data/oa-oauth/lib/omniauth/strategies/foursquare.rb +0 -62
- data/oa-oauth/lib/omniauth/strategies/github.rb +0 -50
- data/oa-oauth/lib/omniauth/strategies/goodreads.rb +0 -44
- data/oa-oauth/lib/omniauth/strategies/google.rb +0 -80
- data/oa-oauth/lib/omniauth/strategies/gowalla.rb +0 -72
- data/oa-oauth/lib/omniauth/strategies/hyves.rb +0 -67
- data/oa-oauth/lib/omniauth/strategies/identica.rb +0 -49
- data/oa-oauth/lib/omniauth/strategies/instagram.rb +0 -56
- data/oa-oauth/lib/omniauth/strategies/instapaper.rb +0 -40
- data/oa-oauth/lib/omniauth/strategies/linked_in.rb +0 -56
- data/oa-oauth/lib/omniauth/strategies/mailru.rb +0 -107
- data/oa-oauth/lib/omniauth/strategies/meetup.rb +0 -56
- data/oa-oauth/lib/omniauth/strategies/miso.rb +0 -41
- data/oa-oauth/lib/omniauth/strategies/mixi.rb +0 -59
- data/oa-oauth/lib/omniauth/strategies/netflix.rb +0 -65
- data/oa-oauth/lib/omniauth/strategies/oauth.rb +0 -83
- data/oa-oauth/lib/omniauth/strategies/oauth2.rb +0 -91
- data/oa-oauth/lib/omniauth/strategies/plurk.rb +0 -58
- data/oa-oauth/lib/omniauth/strategies/qzone.rb +0 -69
- data/oa-oauth/lib/omniauth/strategies/rdio.rb +0 -45
- data/oa-oauth/lib/omniauth/strategies/renren.rb +0 -87
- data/oa-oauth/lib/omniauth/strategies/salesforce.rb +0 -44
- data/oa-oauth/lib/omniauth/strategies/smug_mug.rb +0 -42
- data/oa-oauth/lib/omniauth/strategies/sound_cloud.rb +0 -46
- data/oa-oauth/lib/omniauth/strategies/t163.rb +0 -57
- data/oa-oauth/lib/omniauth/strategies/taobao.rb +0 -79
- data/oa-oauth/lib/omniauth/strategies/teambox.rb +0 -49
- data/oa-oauth/lib/omniauth/strategies/thirty_seven_signals.rb +0 -41
- data/oa-oauth/lib/omniauth/strategies/tqq.rb +0 -64
- data/oa-oauth/lib/omniauth/strategies/trade_me.rb +0 -45
- data/oa-oauth/lib/omniauth/strategies/trip_it.rb +0 -22
- data/oa-oauth/lib/omniauth/strategies/tsina.rb +0 -79
- data/oa-oauth/lib/omniauth/strategies/tsohu.rb +0 -57
- data/oa-oauth/lib/omniauth/strategies/tumblr.rb +0 -60
- data/oa-oauth/lib/omniauth/strategies/twitter.rb +0 -57
- data/oa-oauth/lib/omniauth/strategies/type_pad.rb +0 -76
- data/oa-oauth/lib/omniauth/strategies/vimeo.rb +0 -54
- data/oa-oauth/lib/omniauth/strategies/vkontakte.rb +0 -87
- data/oa-oauth/lib/omniauth/strategies/xauth.rb +0 -67
- data/oa-oauth/lib/omniauth/strategies/yahoo.rb +0 -55
- data/oa-oauth/lib/omniauth/strategies/yammer.rb +0 -43
- data/oa-oauth/lib/omniauth/strategies/you_tube.rb +0 -73
- data/oa-oauth/lib/omniauth/version.rb +0 -19
- data/oa-oauth/oa-oauth.gemspec +0 -32
- data/oa-oauth/spec/fixtures/basecamp_200.xml +0 -24
- data/oa-oauth/spec/fixtures/campfire_200.json +0 -10
- data/oa-oauth/spec/omniauth/strategies/bitly_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/dailymile_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/doit_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/dopplr_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/douban_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/evernote_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/facebook_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/foursquare_spec.rb +0 -18
- data/oa-oauth/spec/omniauth/strategies/github_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/goodreads_spec.rb +0 -6
- data/oa-oauth/spec/omniauth/strategies/google_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/gowalla_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/hyves_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/identica_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/linked_in_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/mailru_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/meetup_spec.rb +0 -14
- data/oa-oauth/spec/omniauth/strategies/miso_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/netflix_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/oauth2_spec.rb +0 -0
- data/oa-oauth/spec/omniauth/strategies/oauth_spec.rb +0 -77
- data/oa-oauth/spec/omniauth/strategies/plurk_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/rdio_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/salesforce_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/smug_mug_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/sound_cloud_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/t163_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/taobao_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/teambox_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/thirty_seven_signals_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/trade_me_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/trip_it_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/tsina_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/tumblr_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/twitter_spec.rb +0 -20
- data/oa-oauth/spec/omniauth/strategies/type_pad_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/vimeo_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/vkontakte_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/yahoo_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/yammer_spec.rb +0 -5
- data/oa-oauth/spec/omniauth/strategies/you_tube_spec.rb +0 -5
- data/oa-oauth/spec/spec_helper.rb +0 -27
- data/oa-oauth/spec/support/shared_examples.rb +0 -29
- data/oa-openid/.gemtest +0 -0
- data/oa-openid/.rspec +0 -3
- data/oa-openid/.yardopts +0 -4
- data/oa-openid/Gemfile +0 -7
- data/oa-openid/LICENSE +0 -19
- data/oa-openid/README.rdoc +0 -51
- data/oa-openid/Rakefile +0 -6
- data/oa-openid/lib/oa-openid.rb +0 -1
- data/oa-openid/lib/omniauth/openid/gapps.rb +0 -32
- data/oa-openid/lib/omniauth/openid.rb +0 -60
- data/oa-openid/lib/omniauth/strategies/google_apps.rb +0 -23
- data/oa-openid/lib/omniauth/strategies/open_id.rb +0 -132
- data/oa-openid/lib/omniauth/strategies/steam.rb +0 -55
- data/oa-openid/lib/omniauth/version.rb +0 -19
- data/oa-openid/oa-openid.gemspec +0 -28
- data/oa-openid/spec/omniauth/strategies/open_id_spec.rb +0 -71
- data/oa-openid/spec/spec_helper.rb +0 -14
- data/omniauth.gemspec +0 -20
- data/tasks/all.rb +0 -134
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
require 'net/http'
|
|
2
|
-
require 'net/https'
|
|
3
|
-
require 'nokogiri'
|
|
4
|
-
|
|
5
|
-
module OmniAuth
|
|
6
|
-
module Strategies
|
|
7
|
-
class CAS
|
|
8
|
-
class ServiceTicketValidator
|
|
9
|
-
|
|
10
|
-
VALIDATION_REQUEST_HEADERS = { 'Accept' => '*/*' }
|
|
11
|
-
|
|
12
|
-
# Build a validator from a +configuration+, a
|
|
13
|
-
# +return_to+ URL, and a +ticket+.
|
|
14
|
-
#
|
|
15
|
-
# @param [OmniAuth::Strategies::CAS::Configuration] configuration the CAS configuration
|
|
16
|
-
# @param [String] return_to_url the URL of this CAS client service
|
|
17
|
-
# @param [String] ticket the service ticket to validate
|
|
18
|
-
def initialize(configuration, return_to_url, ticket)
|
|
19
|
-
@configuration = configuration
|
|
20
|
-
@uri = URI.parse(@configuration.service_validate_url(return_to_url, ticket))
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# Request validation of the ticket from the CAS server's
|
|
24
|
-
# serviceValidate (CAS 2.0) function.
|
|
25
|
-
#
|
|
26
|
-
# Swallows all XML parsing errors (and returns +nil+ in those cases).
|
|
27
|
-
#
|
|
28
|
-
# @return [Hash, nil] a user information hash if the response is valid; +nil+ otherwise.
|
|
29
|
-
#
|
|
30
|
-
# @raise any connection errors encountered.
|
|
31
|
-
def user_info
|
|
32
|
-
parse_user_info(find_authentication_success(get_service_response_body))
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
private
|
|
36
|
-
|
|
37
|
-
# turns an `<cas:authenticationSuccess>` node into a Hash;
|
|
38
|
-
# returns nil if given nil
|
|
39
|
-
def parse_user_info(node)
|
|
40
|
-
return nil if node.nil?
|
|
41
|
-
hash = {}
|
|
42
|
-
node.children.each do |e|
|
|
43
|
-
unless e.kind_of?(Nokogiri::XML::Text) ||
|
|
44
|
-
e.name == 'cas:proxies' ||
|
|
45
|
-
e.name == 'proxies'
|
|
46
|
-
# There are no child elements
|
|
47
|
-
if e.element_children.count == 0
|
|
48
|
-
hash[e.name.sub(/^cas:/, '')] = e.content
|
|
49
|
-
elsif e.element_children.count
|
|
50
|
-
hash[e.name.sub(/^cas:/, '')] = [] if hash[e.name.sub(/^cas:/, '')].nil?
|
|
51
|
-
hash[e.name.sub(/^cas:/, '')].push parse_user_info e
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
hash
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
# finds an `<cas:authenticationSuccess>` node in
|
|
59
|
-
# a `<cas:serviceResponse>` body if present; returns nil
|
|
60
|
-
# if the passed body is nil or if there is no such node.
|
|
61
|
-
def find_authentication_success(body)
|
|
62
|
-
return nil if body.nil? || body == ''
|
|
63
|
-
begin
|
|
64
|
-
doc = Nokogiri::XML(body)
|
|
65
|
-
begin
|
|
66
|
-
doc.xpath('/cas:serviceResponse/cas:authenticationSuccess')
|
|
67
|
-
rescue Nokogiri::XML::XPath::SyntaxError
|
|
68
|
-
doc.xpath('/serviceResponse/authenticationSuccess')
|
|
69
|
-
end
|
|
70
|
-
rescue Nokogiri::XML::XPath::SyntaxError
|
|
71
|
-
nil
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
# retrieves the `<cas:serviceResponse>` XML from the CAS server
|
|
76
|
-
def get_service_response_body
|
|
77
|
-
result = ''
|
|
78
|
-
http = ::Net::HTTP.new(@uri.host, @uri.port)
|
|
79
|
-
http.use_ssl = @uri.port == 443 || @uri.instance_of?(URI::HTTPS)
|
|
80
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl? && @configuration.disable_ssl_verification?
|
|
81
|
-
http.start do |c|
|
|
82
|
-
response = c.get "#{@uri.path}?#{@uri.query}", VALIDATION_REQUEST_HEADERS.dup
|
|
83
|
-
result = response.body
|
|
84
|
-
end
|
|
85
|
-
result
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
end
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
require 'omniauth/enterprise'
|
|
2
|
-
|
|
3
|
-
module OmniAuth
|
|
4
|
-
module Strategies
|
|
5
|
-
class CAS
|
|
6
|
-
include OmniAuth::Strategy
|
|
7
|
-
|
|
8
|
-
autoload :Configuration, 'omniauth/strategies/cas/configuration'
|
|
9
|
-
autoload :ServiceTicketValidator, 'omniauth/strategies/cas/service_ticket_validator'
|
|
10
|
-
|
|
11
|
-
def initialize(app, options = {}, &block)
|
|
12
|
-
super(app, options[:name] || :cas, options.dup, &block)
|
|
13
|
-
@configuration = OmniAuth::Strategies::CAS::Configuration.new(options)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
protected
|
|
17
|
-
|
|
18
|
-
def request_phase
|
|
19
|
-
[
|
|
20
|
-
302,
|
|
21
|
-
{
|
|
22
|
-
'Location' => @configuration.login_url(callback_url),
|
|
23
|
-
'Content-Type' => 'text/plain'
|
|
24
|
-
},
|
|
25
|
-
["You are being redirected to CAS for sign-in."]
|
|
26
|
-
]
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def callback_phase
|
|
30
|
-
ticket = request.params['ticket']
|
|
31
|
-
return fail!(:no_ticket, 'No CAS Ticket') unless ticket
|
|
32
|
-
validator = ServiceTicketValidator.new(@configuration, callback_url, ticket)
|
|
33
|
-
@user_info = validator.user_info
|
|
34
|
-
return fail!(:invalid_ticket, 'Invalid CAS Ticket') if @user_info.nil? || @user_info.empty?
|
|
35
|
-
super
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def auth_hash
|
|
39
|
-
OmniAuth::Utils.deep_merge(super, {
|
|
40
|
-
'uid' => @user_info.delete('user'),
|
|
41
|
-
'extra' => @user_info
|
|
42
|
-
})
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
#this code boughts pieces from activeldap and net-ldap
|
|
2
|
-
|
|
3
|
-
require 'rack'
|
|
4
|
-
require 'net/ldap'
|
|
5
|
-
require 'net/ntlm'
|
|
6
|
-
require 'uri'
|
|
7
|
-
|
|
8
|
-
module OmniAuth
|
|
9
|
-
module Strategies
|
|
10
|
-
class LDAP
|
|
11
|
-
class Adaptor
|
|
12
|
-
class LdapError < StandardError; end
|
|
13
|
-
class ConfigurationError < StandardError; end
|
|
14
|
-
class AuthenticationError < StandardError; end
|
|
15
|
-
class ConnectionError < StandardError; end
|
|
16
|
-
|
|
17
|
-
VALID_ADAPTER_CONFIGURATION_KEYS = [:host, :port, :method, :bind_dn, :password,
|
|
18
|
-
:try_sasl, :sasl_mechanisms, :uid, :base, :allow_anonymous]
|
|
19
|
-
|
|
20
|
-
MUST_HAVE_KEYS = [:host, :port, :method, :uid, :base]
|
|
21
|
-
|
|
22
|
-
METHOD = {
|
|
23
|
-
:ssl => :simple_tls,
|
|
24
|
-
:tls => :start_tls,
|
|
25
|
-
:plain => nil,
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
attr_accessor :bind_dn, :password
|
|
29
|
-
attr_reader :connection, :uid, :base
|
|
30
|
-
|
|
31
|
-
def initialize(configuration={})
|
|
32
|
-
@connection = nil
|
|
33
|
-
@disconnected = false
|
|
34
|
-
@bound = false
|
|
35
|
-
@configuration = configuration.dup
|
|
36
|
-
@configuration[:allow_anonymous] ||= false
|
|
37
|
-
@logger = @configuration.delete(:logger)
|
|
38
|
-
message = []
|
|
39
|
-
MUST_HAVE_KEYS.each do |name|
|
|
40
|
-
message << name if configuration[name].nil?
|
|
41
|
-
end
|
|
42
|
-
raise ArgumentError.new(message.join(",") +" MUST be provided") unless message.empty?
|
|
43
|
-
VALID_ADAPTER_CONFIGURATION_KEYS.each do |name|
|
|
44
|
-
instance_variable_set("@#{name}", configuration[name])
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def connect(options={})
|
|
49
|
-
host = options[:host] || @host
|
|
50
|
-
method = ensure_method(options[:method] || @method || :plain)
|
|
51
|
-
port = options[:port] || @port || ensure_port(method)
|
|
52
|
-
@disconnected = false
|
|
53
|
-
@bound = false
|
|
54
|
-
@bind_tried = false
|
|
55
|
-
|
|
56
|
-
config = {
|
|
57
|
-
:host => host,
|
|
58
|
-
:port => port,
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
config[:encryption] = {:method => method} if method
|
|
62
|
-
|
|
63
|
-
@connection, @uri, @with_start_tls = begin
|
|
64
|
-
uri = construct_uri(host, port, method == :simple_tls)
|
|
65
|
-
with_start_tls = method == :start_tls
|
|
66
|
-
puts ({:uri => uri, :with_start_tls => with_start_tls}).inspect
|
|
67
|
-
[Net::LDAP::Connection.new(config), uri, with_start_tls]
|
|
68
|
-
rescue Net::LDAP::LdapError
|
|
69
|
-
raise ConnectionError, $!.message
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def unbind(options={})
|
|
74
|
-
@connection.close # Net::LDAP doesn't implement unbind.
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def bind(options={})
|
|
78
|
-
connect(options) unless connecting?
|
|
79
|
-
begin
|
|
80
|
-
@bind_tried = true
|
|
81
|
-
|
|
82
|
-
bind_dn = (options[:bind_dn] || @bind_dn).to_s
|
|
83
|
-
try_sasl = options.has_key?(:try_sasl) ? options[:try_sasl] : @try_sasl
|
|
84
|
-
if options.has_key?(:allow_anonymous)
|
|
85
|
-
allow_anonymous = options[:allow_anonymous]
|
|
86
|
-
else
|
|
87
|
-
allow_anonymous = @allow_anonymous
|
|
88
|
-
end
|
|
89
|
-
# Rough bind loop:
|
|
90
|
-
# Attempt 1: SASL if available
|
|
91
|
-
# Attempt 2: SIMPLE with credentials if password block
|
|
92
|
-
# Attempt 3: SIMPLE ANONYMOUS if 1 and 2 fail and allow anonymous is set to true
|
|
93
|
-
if try_sasl and sasl_bind(bind_dn, options)
|
|
94
|
-
puts "bound with sasl"
|
|
95
|
-
elsif simple_bind(bind_dn, options)
|
|
96
|
-
puts "bound with simple"
|
|
97
|
-
elsif allow_anonymous and bind_as_anonymous(options)
|
|
98
|
-
puts "bound as anonymous"
|
|
99
|
-
else
|
|
100
|
-
message = yield if block_given?
|
|
101
|
-
message ||= ('All authentication methods for %s exhausted.') % target
|
|
102
|
-
raise AuthenticationError, message
|
|
103
|
-
end
|
|
104
|
-
@bound = true
|
|
105
|
-
rescue Net::LDAP::LdapError
|
|
106
|
-
raise AuthenticationError, $!.message
|
|
107
|
-
end
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
def disconnect!(options={})
|
|
111
|
-
unbind(options)
|
|
112
|
-
@connection = @uri = @with_start_tls = nil
|
|
113
|
-
@disconnected = true
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
def rebind(options={})
|
|
117
|
-
unbind(options) if bound?
|
|
118
|
-
connect(options)
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
def connecting?
|
|
122
|
-
!@connection.nil? and !@disconnected
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
def bound?
|
|
126
|
-
connecting? and @bound
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
def search(options={}, &block)
|
|
130
|
-
base = options[:base]
|
|
131
|
-
filter = options[:filter]
|
|
132
|
-
limit = options[:limit]
|
|
133
|
-
|
|
134
|
-
args = {
|
|
135
|
-
:base => @base,
|
|
136
|
-
:filter => filter,
|
|
137
|
-
:size => limit
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
attributes = {}
|
|
141
|
-
execute(:search, args) do |entry|
|
|
142
|
-
entry.attribute_names.each do |name|
|
|
143
|
-
attributes[name] = entry[name]
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
|
-
attributes
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
private
|
|
150
|
-
|
|
151
|
-
def execute(method, *args, &block)
|
|
152
|
-
result = @connection.send(method, *args, &block)
|
|
153
|
-
message = nil
|
|
154
|
-
|
|
155
|
-
if result.is_a?(Hash)
|
|
156
|
-
message = result[:errorMessage]
|
|
157
|
-
result = result[:resultCode]
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
unless result.zero?
|
|
161
|
-
message = [Net::LDAP.result2string(result), message].compact.join(": ")
|
|
162
|
-
raise LdapError, message
|
|
163
|
-
end
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
def ensure_port(method)
|
|
167
|
-
if method == :ssl
|
|
168
|
-
URI::LDAPS::DEFAULT_PORT
|
|
169
|
-
else
|
|
170
|
-
URI::LDAP::DEFAULT_PORT
|
|
171
|
-
end
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
def prepare_connection(options)
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
def ensure_method(method)
|
|
178
|
-
method ||= "plain"
|
|
179
|
-
normalized_method = method.to_s.downcase.to_sym
|
|
180
|
-
return METHOD[normalized_method] if METHOD.has_key?(normalized_method)
|
|
181
|
-
|
|
182
|
-
available_methods = METHOD.keys.collect {|m| m.inspect}.join(", ")
|
|
183
|
-
format = "%s is not one of the available connect methods: %s"
|
|
184
|
-
raise ConfigurationError, format % [method.inspect, available_methods]
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
def sasl_bind(bind_dn, options={})
|
|
188
|
-
sasl_mechanisms = options[:sasl_mechanisms] || @sasl_mechanisms
|
|
189
|
-
sasl_mechanisms.each do |mechanism|
|
|
190
|
-
begin
|
|
191
|
-
normalized_mechanism = mechanism.downcase.gsub(/-/, '_')
|
|
192
|
-
sasl_bind_setup = "sasl_bind_setup_#{normalized_mechanism}"
|
|
193
|
-
next unless respond_to?(sasl_bind_setup, true)
|
|
194
|
-
initial_credential, challenge_response = send(sasl_bind_setup, bind_dn, options)
|
|
195
|
-
|
|
196
|
-
args = {
|
|
197
|
-
:method => :sasl,
|
|
198
|
-
:initial_credential => initial_credential,
|
|
199
|
-
:mechanism => mechanism,
|
|
200
|
-
:challenge_response => challenge_response,
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
info = {
|
|
204
|
-
:name => "bind: SASL", :dn => bind_dn, :mechanism => mechanism,
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
execute(:bind, args)
|
|
208
|
-
return true
|
|
209
|
-
|
|
210
|
-
rescue Exception => e
|
|
211
|
-
puts e.message
|
|
212
|
-
end
|
|
213
|
-
end
|
|
214
|
-
false
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
def sasl_bind_setup_digest_md5(bind_dn, options)
|
|
218
|
-
initial_credential = ""
|
|
219
|
-
challenge_response = Proc.new do |cred|
|
|
220
|
-
pref = SASL::Preferences.new :digest_uri => "ldap/#{@host}", :username => bind_dn, :has_password? => true, :password => options[:password]||@password
|
|
221
|
-
sasl = SASL.new("DIGEST-MD5", pref)
|
|
222
|
-
response = sasl.receive("challenge", cred)
|
|
223
|
-
response[1]
|
|
224
|
-
end
|
|
225
|
-
[initial_credential, challenge_response]
|
|
226
|
-
end
|
|
227
|
-
|
|
228
|
-
def sasl_bind_setup_gss_spnego(bind_dn, options)
|
|
229
|
-
puts options.inspect
|
|
230
|
-
user,psw = [bind_dn, options[:password]||@password]
|
|
231
|
-
raise LdapError.new( "invalid binding information" ) unless (user && psw)
|
|
232
|
-
|
|
233
|
-
nego = proc {|challenge|
|
|
234
|
-
t2_msg = Net::NTLM::Message.parse( challenge )
|
|
235
|
-
user, domain = user.split('\\').reverse
|
|
236
|
-
t2_msg.target_name = Net::NTLM::encode_utf16le(domain) if domain
|
|
237
|
-
t3_msg = t2_msg.response( {:user => user, :password => psw}, {:ntlmv2 => true} )
|
|
238
|
-
t3_msg.serialize
|
|
239
|
-
}
|
|
240
|
-
[Net::NTLM::Message::Type1.new.serialize, nego]
|
|
241
|
-
end
|
|
242
|
-
|
|
243
|
-
def simple_bind(bind_dn, options={})
|
|
244
|
-
args = {
|
|
245
|
-
:method => :simple,
|
|
246
|
-
:username => bind_dn,
|
|
247
|
-
:password => (options[:password]||@password).to_s,
|
|
248
|
-
}
|
|
249
|
-
begin
|
|
250
|
-
raise AuthenticationError if args[:password] == ""
|
|
251
|
-
execute(:bind, args)
|
|
252
|
-
true
|
|
253
|
-
rescue Exception
|
|
254
|
-
false
|
|
255
|
-
end
|
|
256
|
-
end
|
|
257
|
-
|
|
258
|
-
def bind_as_anonymous(options={})
|
|
259
|
-
execute(:bind, {:method => :anonymous})
|
|
260
|
-
true
|
|
261
|
-
end
|
|
262
|
-
|
|
263
|
-
def construct_uri(host, port, ssl)
|
|
264
|
-
protocol = ssl ? "ldaps" : "ldap"
|
|
265
|
-
URI.parse("#{protocol}://#{host}:#{port}").to_s
|
|
266
|
-
end
|
|
267
|
-
|
|
268
|
-
def target
|
|
269
|
-
return nil if @uri.nil?
|
|
270
|
-
if @with_start_tls
|
|
271
|
-
"#{@uri}(StartTLS)"
|
|
272
|
-
else
|
|
273
|
-
@uri
|
|
274
|
-
end
|
|
275
|
-
end
|
|
276
|
-
end
|
|
277
|
-
end
|
|
278
|
-
end
|
|
279
|
-
end
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
require 'omniauth/enterprise'
|
|
2
|
-
require 'net/ldap'
|
|
3
|
-
require 'sasl/base'
|
|
4
|
-
require 'sasl'
|
|
5
|
-
|
|
6
|
-
module OmniAuth
|
|
7
|
-
module Strategies
|
|
8
|
-
class LDAP
|
|
9
|
-
include OmniAuth::Strategy
|
|
10
|
-
|
|
11
|
-
autoload :Adaptor, 'omniauth/strategies/ldap/adaptor'
|
|
12
|
-
@@config = {'name' => 'cn',
|
|
13
|
-
'first_name' => 'givenName',
|
|
14
|
-
'last_name' => 'sn',
|
|
15
|
-
'email' => ['mail', "email", 'userPrincipalName'],
|
|
16
|
-
'phone' => ['telephoneNumber', 'homePhone', 'facsimileTelephoneNumber'],
|
|
17
|
-
'mobile_number' => ['mobile', 'mobileTelephoneNumber'],
|
|
18
|
-
'nickname' => ['uid', 'userid', 'sAMAccountName'],
|
|
19
|
-
'title' => 'title',
|
|
20
|
-
'location' => {"%0, %1, %2, %3 %4" => [['address', 'postalAddress', 'homePostalAddress', 'street', 'streetAddress'], ['l'], ['st'],['co'],['postOfficeBox']]},
|
|
21
|
-
'uid' => 'dn',
|
|
22
|
-
'url' => ['wwwhomepage'],
|
|
23
|
-
'image' => 'jpegPhoto',
|
|
24
|
-
'description' => 'description'}
|
|
25
|
-
|
|
26
|
-
# Initialize the LDAP Middleware
|
|
27
|
-
#
|
|
28
|
-
# @param [Rack Application] app Standard Rack middleware argument.
|
|
29
|
-
# @option options [String, 'LDAP Authentication'] :title A title for the authentication form.
|
|
30
|
-
def initialize(app, options = {}, &block)
|
|
31
|
-
super(app, options[:name] || :ldap, options.dup, &block)
|
|
32
|
-
@name_proc = (@options.delete(:name_proc) || Proc.new {|name| name})
|
|
33
|
-
@adaptor = OmniAuth::Strategies::LDAP::Adaptor.new(options)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
protected
|
|
37
|
-
|
|
38
|
-
def request_phase
|
|
39
|
-
if env['REQUEST_METHOD'] == 'GET'
|
|
40
|
-
get_credentials
|
|
41
|
-
else
|
|
42
|
-
session['omniauth.ldap'] = {'username' => request['username'], 'password' => request['password']}
|
|
43
|
-
redirect callback_path
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def get_credentials
|
|
48
|
-
OmniAuth::Form.build(:title => (options[:title] || "LDAP Authentication")) do
|
|
49
|
-
text_field 'Login', 'username'
|
|
50
|
-
password_field 'Password', 'password'
|
|
51
|
-
end.to_response
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def callback_phase
|
|
55
|
-
begin
|
|
56
|
-
creds = session['omniauth.ldap']
|
|
57
|
-
session.delete 'omniauth.ldap'
|
|
58
|
-
@ldap_user_info = {}
|
|
59
|
-
begin
|
|
60
|
-
(@adaptor.bind(:allow_anonymous => true) unless @adaptor.bound?)
|
|
61
|
-
rescue Exception => e
|
|
62
|
-
puts "failed to bind with the default credentials: " + e.message
|
|
63
|
-
end
|
|
64
|
-
@ldap_user_info = @adaptor.search(:filter => Net::LDAP::Filter.eq(@adaptor.uid, @name_proc.call(creds['username'])),:limit => 1) if @adaptor.bound?
|
|
65
|
-
bind_dn = creds['username']
|
|
66
|
-
bind_dn = @ldap_user_info[:dn].to_a.first if @ldap_user_info[:dn]
|
|
67
|
-
@adaptor.bind(:bind_dn => bind_dn, :password => creds['password'])
|
|
68
|
-
@ldap_user_info = @adaptor.search(:filter => Net::LDAP::Filter.eq(@adaptor.uid, @name_proc.call(creds['username'])),:limit => 1) if @ldap_user_info.empty?
|
|
69
|
-
@user_info = self.class.map_user(@@config, @ldap_user_info)
|
|
70
|
-
|
|
71
|
-
@env['omniauth.auth'] = auth_hash
|
|
72
|
-
|
|
73
|
-
rescue Exception => e
|
|
74
|
-
return fail!(:invalid_credentials, e)
|
|
75
|
-
end
|
|
76
|
-
call_app!
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
def auth_hash
|
|
80
|
-
OmniAuth::Utils.deep_merge(super, {
|
|
81
|
-
'uid' => @user_info["uid"],
|
|
82
|
-
'user_info' => @user_info,
|
|
83
|
-
'extra' => @ldap_user_info
|
|
84
|
-
})
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
def self.map_user(mapper, object)
|
|
88
|
-
user = {}
|
|
89
|
-
mapper.each do |key, value|
|
|
90
|
-
case value
|
|
91
|
-
when String
|
|
92
|
-
user[key] = object[value.downcase.to_sym].to_s if object[value.downcase.to_sym]
|
|
93
|
-
when Array
|
|
94
|
-
value.each {|v| (user[key] = object[v.downcase.to_sym].to_s; break;) if object[v.downcase.to_sym]}
|
|
95
|
-
when Hash
|
|
96
|
-
value.map do |key1, value1|
|
|
97
|
-
pattern = key1.dup
|
|
98
|
-
value1.each_with_index do |v,i|
|
|
99
|
-
part = '';
|
|
100
|
-
v.each {|v1| (part = object[v1.downcase.to_sym].to_s; break;) if object[v1.downcase.to_sym]}
|
|
101
|
-
pattern.gsub!("%#{i}",part||'')
|
|
102
|
-
end
|
|
103
|
-
user[key] = pattern
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
user
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
module OmniAuth
|
|
2
|
-
module Version
|
|
3
|
-
unless defined?(::OmniAuth::Version::MAJOR)
|
|
4
|
-
MAJOR = 0
|
|
5
|
-
end
|
|
6
|
-
unless defined?(::OmniAuth::Version::MINOR)
|
|
7
|
-
MINOR = 2
|
|
8
|
-
end
|
|
9
|
-
unless defined?(::OmniAuth::Version::PATCH)
|
|
10
|
-
PATCH = 6
|
|
11
|
-
end
|
|
12
|
-
unless defined?(::OmniAuth::Version::PRE)
|
|
13
|
-
PRE = nil
|
|
14
|
-
end
|
|
15
|
-
unless defined?(::OmniAuth::Version::STRING)
|
|
16
|
-
STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
|
2
|
-
require File.expand_path('../lib/omniauth/version', __FILE__)
|
|
3
|
-
|
|
4
|
-
Gem::Specification.new do |gem|
|
|
5
|
-
gem.add_runtime_dependency 'addressable', '2.2.4'
|
|
6
|
-
gem.add_runtime_dependency 'nokogiri', '~> 1.4.2'
|
|
7
|
-
gem.add_runtime_dependency 'net-ldap', '~> 0.2.2'
|
|
8
|
-
gem.add_runtime_dependency 'oa-core', OmniAuth::Version::STRING
|
|
9
|
-
gem.add_runtime_dependency 'pyu-ruby-sasl', '~> 0.0.3.1'
|
|
10
|
-
gem.add_runtime_dependency 'rubyntlm', '~> 0.1.1'
|
|
11
|
-
gem.add_development_dependency 'maruku', '~> 0.6'
|
|
12
|
-
gem.add_development_dependency 'simplecov', '~> 0.4'
|
|
13
|
-
gem.add_development_dependency 'rack-test', '~> 0.5'
|
|
14
|
-
gem.add_development_dependency 'rake', '~> 0.8'
|
|
15
|
-
gem.add_development_dependency 'rspec', '~> 2.5'
|
|
16
|
-
gem.add_development_dependency 'webmock', '~> 1.6'
|
|
17
|
-
gem.add_development_dependency 'yard', '~> 0.7'
|
|
18
|
-
gem.add_development_dependency 'ZenTest', '~> 4.5'
|
|
19
|
-
gem.name = 'oa-enterprise'
|
|
20
|
-
gem.version = OmniAuth::Version::STRING
|
|
21
|
-
gem.description = %q{Enterprise strategies for OmniAuth.}
|
|
22
|
-
gem.summary = gem.description
|
|
23
|
-
gem.email = ['james.a.rosen@gmail.com', 'ping@intridea.com', 'michael@intridea.com', 'sferik@gmail.com']
|
|
24
|
-
gem.homepage = 'http://github.com/intridea/omniauth'
|
|
25
|
-
gem.authors = ['James A. Rosen', 'Ping Yu', 'Michael Bleigh', 'Erik Michaels-Ober']
|
|
26
|
-
gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
|
|
27
|
-
gem.files = `git ls-files`.split("\n")
|
|
28
|
-
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
29
|
-
gem.require_paths = ['lib']
|
|
30
|
-
gem.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') if gem.respond_to? :required_rubygems_version=
|
|
31
|
-
end
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>
|
|
2
|
-
<cas:authenticationSuccess>
|
|
3
|
-
<cas:user>psegel</cas:user>
|
|
4
|
-
<cas:first-name>Peter</cas:first-name>
|
|
5
|
-
<cas:last-name>Segel</cas:last-name>
|
|
6
|
-
<hire-date>2004-07-13</hire-date>
|
|
7
|
-
</cas:authenticationSuccess>
|
|
8
|
-
</cas:serviceResponse>
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
require File.expand_path('../../../spec_helper', __FILE__)
|
|
2
|
-
require 'cgi'
|
|
3
|
-
|
|
4
|
-
describe OmniAuth::Strategies::CAS, :type => :strategy do
|
|
5
|
-
|
|
6
|
-
include OmniAuth::Test::StrategyTestCase
|
|
7
|
-
|
|
8
|
-
def strategy
|
|
9
|
-
@cas_server ||= 'https://cas.example.org'
|
|
10
|
-
[OmniAuth::Strategies::CAS, {:cas_server => @cas_server}]
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
describe 'GET /auth/cas' do
|
|
14
|
-
before do
|
|
15
|
-
get '/auth/cas'
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it 'should redirect to the CAS server' do
|
|
19
|
-
last_response.should be_redirect
|
|
20
|
-
return_to = CGI.escape(last_request.url + '/callback')
|
|
21
|
-
last_response.headers['Location'].should == @cas_server + '/login?service=' + return_to
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
describe 'GET /auth/cas/callback without a ticket' do
|
|
26
|
-
before do
|
|
27
|
-
get '/auth/cas/callback'
|
|
28
|
-
end
|
|
29
|
-
it 'should fail' do
|
|
30
|
-
last_response.should be_redirect
|
|
31
|
-
last_response.headers['Location'].should =~ /no_ticket/
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
describe 'GET /auth/cas/callback with an invalid ticket' do
|
|
36
|
-
before do
|
|
37
|
-
stub_request(:get, /^https:\/\/cas.example.org(:443)?\/serviceValidate\?([^&]+&)?ticket=9391d/).
|
|
38
|
-
to_return(:body => File.read(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cas_failure.xml')))
|
|
39
|
-
get '/auth/cas/callback?ticket=9391d'
|
|
40
|
-
end
|
|
41
|
-
it 'should fail' do
|
|
42
|
-
last_response.should be_redirect
|
|
43
|
-
last_response.headers['Location'].should =~ /invalid_ticket/
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
describe 'GET /auth/cas/callback with a valid ticket' do
|
|
48
|
-
before do
|
|
49
|
-
stub_request(:get, /^https:\/\/cas.example.org(:443)?\/serviceValidate\?([^&]+&)?ticket=593af/).
|
|
50
|
-
with { |request| @request_uri = request.uri.to_s }.
|
|
51
|
-
to_return(:body => File.read(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cas_success.xml')))
|
|
52
|
-
get '/auth/cas/callback?ticket=593af'
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it 'should strip the ticket parameter from the callback URL before sending it to the CAS server' do
|
|
56
|
-
@request_uri.scan('ticket=').length.should == 1
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
sets_an_auth_hash
|
|
60
|
-
sets_provider_to 'cas'
|
|
61
|
-
sets_uid_to 'psegel'
|
|
62
|
-
|
|
63
|
-
it 'should set additional user information' do
|
|
64
|
-
extra = (last_request.env['omniauth.auth'] || {})['extra']
|
|
65
|
-
extra.should be_kind_of(Hash)
|
|
66
|
-
extra['first-name'].should == 'Peter'
|
|
67
|
-
extra['last-name'].should == 'Segel'
|
|
68
|
-
extra['hire-date'].should == '2004-07-13'
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it 'should call through to the master app' do
|
|
72
|
-
last_response.body.should == 'true'
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
unless RUBY_VERSION =~ /^1\.8\.\d$/
|
|
77
|
-
describe 'GET /auth/cas/callback with a valid ticket and gzipped response from the server on ruby >1.8' do
|
|
78
|
-
before do
|
|
79
|
-
zipped = StringIO.new
|
|
80
|
-
Zlib::GzipWriter.wrap zipped do |io|
|
|
81
|
-
io.write File.read(File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'cas_success.xml'))
|
|
82
|
-
end
|
|
83
|
-
stub_request(:get, /^https:\/\/cas.example.org(:443)?\/serviceValidate\?([^&]+&)?ticket=593af/).
|
|
84
|
-
with { |request| @request_uri = request.uri.to_s }.
|
|
85
|
-
to_return(:body => zipped.string, :headers => { 'content-encoding' => 'gzip' })
|
|
86
|
-
get '/auth/cas/callback?ticket=593af'
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
it 'should call through to the master app when response is gzipped' do
|
|
90
|
-
last_response.body.should == 'true'
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|