omniauth-wsfed 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTdjMWJkYzEyNmNmNDZmNzRlMzlhN2IzYmZmMGY4MzM1ZTBkNTRmOA==
4
+ MDVjMGFmYjFiNmU3MjQxYjk1YmJiYjg4MmMzMTk5MmU0ZTJjZDdlZQ==
5
5
  data.tar.gz: !binary |-
6
- ODhlOTYxY2E5M2ZlMjBiZGIzNTFiYTUzNzQ2N2FjMDRlYTdlMDJhMA==
6
+ YzQwNjJmOWQ2MjU3OGQ1NjMwYjNiOGI1MWRkNWM1YTFjYTNhMDkyOQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- OWU2OTYzMDBhNDE4Y2YyY2NmOGNhNjM4MWVjMTUyMmE4MzYwNjI1NjFhMWM5
10
- NGIxY2YwNGYwNTk1YjdjNTdiOGE0NTlmODdlZDY1YjA4NDU4MWI5NDc0YWM0
11
- ZmQ4YjE2MmM3NjNlNGY3N2QwNzY4ZTU5Nzc4Mzc4ZjFjNzVjNjY=
9
+ MTIwYjdjZDQwZWVlZjJkNDlmODc1MmRjMDc3ODU5Njk0YTg2YjQ0OTNjNDkz
10
+ YTY2ZDM5NjNkMjM3MmUzMTNkMDg3ZjM0YzMyMjJjOTIxN2UxNTIzZmYzYjJl
11
+ NmY1YjA5NjVlMDgxOTJjN2M0YTIzYzFmODg0Y2VlOTYwMzVkMzU=
12
12
  data.tar.gz: !binary |-
13
- MTAyMDc4ZWZlYWMwZjQ5YTI0M2RiNGVlYTExMmIyNzJkMzZmZWFhY2EzZjQ1
14
- YjY4ZTllNTE4ZWQ0MDZlZGIwN2QwNWU3YmZhNWU0NTAyYzE2MTRjYjUwODVk
15
- ZWZhYmQzMjE5ZjBkNTM2YmUzMWNjMjJhNzMyN2JhMTcyMzE4NDc=
13
+ MGZlNGRiMGQwYmNhNjMyYThkMGQwOTE3MjM3ZGJkMzhmNGY4Y2U3NzlmMjgy
14
+ MDk2YjEzOTE2YWFlNGM2NWM4YzAyNGY5ZjAzYzE0M2Q5ODJiOGRhNDFlYTIx
15
+ Yzg4MjE3MzQyZTI1YTQ0Yjk4NWRhOGRhZTQ4NDg5M2U2MDdlNzI=
data/.gitignore CHANGED
@@ -3,8 +3,10 @@
3
3
 
4
4
  #RVM
5
5
  .rvmrc
6
+ .ruby-version
7
+ .ruby-gemset
6
8
 
7
9
  #Other
8
10
  .DS_Store
9
11
  *.gem
10
-
12
+ Gemfile.lock
data/.travis.yml CHANGED
@@ -1,5 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
3
  - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - rbx-19mode
7
+ - jruby-19mode
5
8
  script: bundle exec rspec spec
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module WSFed
3
- VERSION = '0.2.1'
3
+ VERSION = '0.2.2'
4
4
  end
5
5
  end
@@ -14,23 +14,15 @@ module OmniAuth
14
14
 
15
15
  # Issues passive WS-Federation redirect for authentication...
16
16
  def request_phase
17
- whr = @request.params['whr']
18
-
19
- if !whr.nil?
20
- request = OmniAuth::Strategies::WSFed::AuthRequest.new
21
- redirect(request.create(options, :whr => whr))
22
- elsif !options[:home_realm_discovery_path].nil?
23
- redirect(options[:home_realm_discovery_path])
24
- else
25
- request = OmniAuth::Strategies::WSFed::AuthRequest.new
26
- redirect(request.create(options))
27
- end
28
-
17
+ auth_request = OmniAuth::Strategies::WSFed::AuthRequest.new(options, :whr => @request.params['whr'])
18
+ redirect(auth_request.redirect_url)
29
19
  end
30
20
 
31
21
  # Parse SAML token...
32
22
  def callback_phase
33
23
  begin
24
+ validate_callback_params(@request)
25
+
34
26
  wsfed_callback = request.params['wresult']
35
27
 
36
28
  signed_document = OmniAuth::Strategies::WSFed::XMLSecurity::SignedDocument.new(wsfed_callback)
@@ -68,7 +60,13 @@ module OmniAuth
68
60
  options[:idp_cert_fingerprint]
69
61
  else
70
62
  cert = OpenSSL::X509::Certificate.new(options[:idp_cert].gsub(/^ +/, ''))
71
- Digest::SHA1.hexdigest(cert.to_der).upcase.scan(/../).join(":")
63
+ Digest::SHA1.hexdigest(cert.to_der).upcase.scan(/../).join(':')
64
+ end
65
+ end
66
+
67
+ def validate_callback_params(request)
68
+ if request.params['wresult'].nil? || request.params['wresult'].empty?
69
+ raise OmniAuth::Strategies::WSFed::ValidationError.new('AuthN token (wresult) missing in callback.')
72
70
  end
73
71
  end
74
72
 
@@ -9,10 +9,27 @@ module OmniAuth
9
9
 
10
10
  SIGNIN_PARAM = 'wsignin1.0'
11
11
 
12
- def create (settings, args = {})
12
+ attr_reader :strategy_settings, :args
13
+
14
+ def initialize(settings, args = {})
15
+ raise ArgumentError.new('OmniAuth-WSFed settings cannot be nil.') if settings.nil?
16
+
17
+ @strategy_settings = settings
18
+ @args = args
19
+ end
20
+
21
+ def redirect_url
22
+ if args[:whr].nil? && strategy_settings[:home_realm_discovery_path]
23
+ strategy_settings[:home_realm_discovery_path]
24
+ else
25
+ wsfed_signin_request
26
+ end
27
+ end
28
+
29
+ def wsfed_signin_request
13
30
  wa = SIGNIN_PARAM
14
- wtrealm = url_encode(settings[:realm])
15
- wreply = url_encode(settings[:reply])
31
+ wtrealm = url_encode(strategy_settings[:realm])
32
+ wreply = url_encode(strategy_settings[:reply])
16
33
  wct = url_encode(Time.now.utc)
17
34
  whr = url_encode(args[:whr])
18
35
 
@@ -22,7 +39,7 @@ module OmniAuth
22
39
  query_string = "#{query_string}&whr=#{whr}"
23
40
  end
24
41
 
25
- settings[:issuer] + query_string
42
+ strategy_settings[:issuer] + query_string
26
43
  end
27
44
 
28
45
  end
@@ -3,64 +3,101 @@ require 'erb'
3
3
 
4
4
  describe OmniAuth::Strategies::WSFed::AuthRequest do
5
5
 
6
- context 'Valid Request' do
7
-
8
- let(:wsfed_settings) do
9
- {
10
- issuer: "https://c4sc.accesscontrol.windows.net.com/v2/wsfederation",
11
- realm: "http://c4sc.com/security_realm",
12
- reply: "http://rp.c4sc.com/auth/wsfed"
13
- }
6
+ let(:wsfed_settings) do
7
+ {
8
+ :issuer => 'https://c4sc.accesscontrol.windows.net.com/v2/wsfederation',
9
+ :realm => 'http://c4sc.com/security_realm',
10
+ :reply => 'http://rp.c4sc.com/auth/wsfed',
11
+ :home_realm_discovery_path => 'auth/home_realm_discovery'
12
+ }
13
+ end
14
+
15
+ context 'Initialization' do
16
+
17
+ it 'should raise an ArgumentException when strategy_settings are nil or empty' do
18
+ expect { OmniAuth::Strategies::WSFed::AuthRequest.new(nil, {}) }.to raise_error ArgumentError
14
19
  end
15
20
 
16
- describe 'WsFed Auth Request URL' do
21
+ it 'should set strategy_settings and args properties when initialized properly' do
22
+ args = { :whr => 'https://identity.c4sc.com'}
23
+ request = OmniAuth::Strategies::WSFed::AuthRequest.new(wsfed_settings, args)
17
24
 
18
- let :request do
19
- OmniAuth::Strategies::WSFed::AuthRequest.new.create(wsfed_settings)
20
- end
25
+ request.strategy_settings.should == wsfed_settings
26
+ request.args.should == args
27
+ end
21
28
 
22
- it 'should include the issuer URL followed by WsFed query string params' do
23
- request.should start_with "#{wsfed_settings[:issuer]}?"
24
- end
29
+ end
25
30
 
26
- it 'should include the sign-in param [wa]' do
27
- request.should include 'wa=wsignin1.0'
28
- end
31
+ context 'Redirect URL' do
29
32
 
30
- it 'should include the url-encoded security realm param [wtrealm]' do
31
- request.should include "wtrealm=#{ERB::Util::url_encode(wsfed_settings[:realm])}"
32
- end
33
+ it 'should equal the :home_realm_discovery path if configured and no :whr argument exists' do
34
+ request = OmniAuth::Strategies::WSFed::AuthRequest.new(wsfed_settings, {})
33
35
 
34
- it 'should include the url-encoded reply param [wreply]' do
35
- request.should include "wreply=#{ERB::Util::url_encode(wsfed_settings[:reply])}"
36
- end
36
+ request.redirect_url.should == wsfed_settings[:home_realm_discovery_path]
37
+ end
37
38
 
38
- it 'should include an empty context param [wctx]' do
39
- request.should include "wctx=&"
40
- end
39
+ it 'should equal the wsfed_signin_path if :whr argument exists' do
40
+ args = { :whr => 'https://identity.c4sc.com'}
41
+ request = OmniAuth::Strategies::WSFed::AuthRequest.new(wsfed_settings, args)
42
+
43
+ request.redirect_url.should == request.wsfed_signin_request
44
+ end
41
45
 
42
- it 'should include the request creation instant time param [wtc]' do
43
- time = Time.now.utc
44
- Time.now.stub(:utc).and_return(time)
46
+ it 'should equal the wsfed_signin_path if :whr argument and :home_realm_discovery_path are missing' do
47
+ wsfed_settings.delete(:home_realm_discovery_path)
48
+ request = OmniAuth::Strategies::WSFed::AuthRequest.new(wsfed_settings, {})
45
49
 
46
- request.should include "wct=#{ERB::Util.url_encode(time)}"
47
- end
50
+ request.redirect_url.should == request.wsfed_signin_request
51
+ end
52
+
53
+ end
48
54
 
49
- describe 'Url-Encoded Home Realm Parameter [whr]' do
55
+ context 'WSFed Signin Request' do
50
56
 
51
- let(:home_realm) { "http://identity.c4sc.com/trust" }
57
+ let :request do
58
+ OmniAuth::Strategies::WSFed::AuthRequest.new(wsfed_settings)
59
+ end
52
60
 
53
- it 'should include [whr] if provided in the options' do
54
- request = OmniAuth::Strategies::WSFed::AuthRequest.new.create(wsfed_settings, :whr => home_realm)
55
- request.should include "whr=#{ERB::Util::url_encode(home_realm)}"
56
- end
61
+ it 'should include the issuer URL followed by WsFed query string params' do
62
+ request.wsfed_signin_request.should start_with "#{request.strategy_settings[:issuer]}?"
63
+ end
64
+
65
+ it 'should include the sign-in param [wa]' do
66
+ request.wsfed_signin_request.should include 'wa=wsignin1.0'
67
+ end
68
+
69
+ it 'should include the url-encoded security realm param [wtrealm]' do
70
+ request.wsfed_signin_request.should include "wtrealm=#{ERB::Util::url_encode(request.strategy_settings[:realm])}"
71
+ end
72
+
73
+ it 'should include the url-encoded reply param [wreply]' do
74
+ request.wsfed_signin_request.should include "wreply=#{ERB::Util::url_encode(request.strategy_settings[:reply])}"
75
+ end
57
76
 
58
- it 'should exclude [whr] if ignored in the options' do
59
- request = OmniAuth::Strategies::WSFed::AuthRequest.new.create(wsfed_settings, :whr => nil)
60
- request.should_not include "whr=#{ERB::Util::url_encode(home_realm)}"
61
- request.should_not include "whr="
62
- end
77
+ it 'should include an empty context param [wctx]' do
78
+ request.wsfed_signin_request.should include "wctx=&"
79
+ end
80
+
81
+ it 'should include the request creation instant time param [wtc]' do
82
+ time = Time.now.utc
83
+ Time.now.stub(:utc).and_return(time)
84
+
85
+ request.wsfed_signin_request.should include "wct=#{ERB::Util.url_encode(time)}"
86
+ end
87
+
88
+ describe 'Url-Encoded Home Realm Parameter [whr]' do
89
+
90
+ let(:home_realm) { 'http://identity.c4sc.com/trust' }
91
+
92
+ it 'should include [whr] if provided in the options' do
93
+ request = OmniAuth::Strategies::WSFed::AuthRequest.new(wsfed_settings, :whr => home_realm)
94
+ request.wsfed_signin_request.should include "whr=#{ERB::Util::url_encode(home_realm)}"
95
+ end
63
96
 
97
+ it 'should exclude [whr] if ignored in the options' do
98
+ request = OmniAuth::Strategies::WSFed::AuthRequest.new(wsfed_settings, :whr => nil)
99
+ request.wsfed_signin_request.should_not include "whr=#{ERB::Util::url_encode(home_realm)}"
100
+ request.wsfed_signin_request.should_not include 'whr='
64
101
  end
65
102
 
66
103
  end
@@ -1,22 +1,22 @@
1
1
  require 'spec_helper'
2
2
 
3
- # Had to split these tests into two different classes because the OmniAuth::Test::StrategyTestCase only sets up one
4
- # instance of the strategy settings per spec description. In other words, any time you need to make changes to the
5
- # OmniAuth initialization settings, you need a new spec description to re-initialize the test strategy.
3
+ # Had to split these tests into different classes because the OmniAuth::Test::StrategyTestCase only
4
+ # sets up one instance of the strategy settings per spec description. In other words, any time you
5
+ # need to make changes to the OmniAuth initialization settings, you need a new spec description to
6
+ # re-initialize the test strategy.
6
7
 
7
8
  describe OmniAuth::Strategies::WSFed, :type => :strategy do
8
9
  include OmniAuth::Test::StrategyTestCase
9
10
 
10
- let(:auth_hash){ last_request.env['omniauth.auth'] }
11
11
  let(:wsfed_settings) do
12
12
  {
13
- issuer: "https://c4sc.accesscontrol.windows.net.com/v2/wsfederation",
14
- realm: "http://c4sc.com/security_realm",
15
- reply: "http://rp.c4sc.com/auth/wsfed"
13
+ :issuer => 'https://c4sc.accesscontrol.windows.net.com/v2/wsfederation',
14
+ :realm => 'http://example.com/rp',
15
+ :reply => 'http://example.com/auth/wsfed'
16
16
  }
17
17
  end
18
18
  let(:strategy) { [OmniAuth::Strategies::WSFed, wsfed_settings] }
19
- let(:home_realm) { "http://identity.c4sc.com/trust" }
19
+ let(:home_realm) { 'http://identity.c4sc.com' }
20
20
 
21
21
 
22
22
  describe 'request_phase: GET /auth/wsfed' do
@@ -47,17 +47,16 @@ end
47
47
  describe OmniAuth::Strategies::WSFed, :type => :strategy do
48
48
  include OmniAuth::Test::StrategyTestCase
49
49
 
50
- let(:home_realm_discovery) { "/auth/wsfed/home_realm_discovery" }
51
50
  let(:wsfed_settings) do
52
51
  {
53
- issuer: "https://c4sc.accesscontrol.windows.net.com/v2/wsfederation",
54
- realm: "http://c4sc.com/security_realm",
55
- reply: "http://rp.c4sc.com/auth/wsfed",
56
- home_realm_discovery_path: home_realm_discovery
52
+ :issuer => 'https://c4sc.accesscontrol.windows.net.com/v2/wsfederation',
53
+ :realm => 'http://example.com/rp',
54
+ :reply => 'http://example.com/auth/wsfed',
55
+ :home_realm_discovery_path => '/auth/wsfed/home_realm_discovery'
57
56
  }
58
57
  end
59
58
  let(:strategy) { [OmniAuth::Strategies::WSFed, wsfed_settings] }
60
- let(:home_realm) { "http://identity.c4sc.com/trust" }
59
+ let(:home_realm) { 'http://identity.c4sc.com' }
61
60
 
62
61
  context ':home_realm_discovery_path configured' do
63
62
 
@@ -65,7 +64,7 @@ describe OmniAuth::Strategies::WSFed, :type => :strategy do
65
64
  get '/auth/wsfed'
66
65
 
67
66
  last_response.should be_redirect
68
- last_response.location.should == home_realm_discovery
67
+ last_response.location.should == wsfed_settings[:home_realm_discovery_path]
69
68
  end
70
69
 
71
70
  it 'should redirect to the IdP/FP Issuer URL and maintain [whr] param' do
@@ -79,4 +78,31 @@ describe OmniAuth::Strategies::WSFed, :type => :strategy do
79
78
  end
80
79
  end
81
80
 
81
+ describe OmniAuth::Strategies::WSFed, :type => :strategy do
82
+ include OmniAuth::Test::StrategyTestCase
83
+
84
+ let(:home_realm_discovery) { '/auth/wsfed/home_realm_discovery' }
85
+ let(:wsfed_settings) do
86
+ {
87
+ :issuer => 'https://c4sc.accesscontrol.windows.net.com/v2/wsfederation',
88
+ :realm => 'http://example.com/rp',
89
+ :reply => 'http://example.com/auth/wsfed',
90
+ :home_realm_discovery_path => home_realm_discovery
91
+ }
92
+ end
93
+ let(:strategy) { [OmniAuth::Strategies::WSFed, wsfed_settings] }
94
+ let(:home_realm) { 'http://identity.c4sc.com' }
95
+
96
+ context 'invalid callbacks' do
97
+
98
+ it 'should redirect to failure route when the \'wresult\' parameter is nil' do
99
+ post 'auth/wsfed/callback'
100
+
101
+ last_response.status.should == 302
102
+ last_response.location.should == '/auth/failure?message=invalid_authn_token&strategy=wsfed'
103
+ end
104
+
105
+ end
106
+ end
107
+
82
108
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-wsfed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Beckman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-11 00:00:00.000000000 Z
11
+ date: 2013-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: omniauth
@@ -93,7 +93,6 @@ files:
93
93
  - .gitignore
94
94
  - .travis.yml
95
95
  - Gemfile
96
- - Gemfile.lock
97
96
  - LICENSE
98
97
  - README.md
99
98
  - Rakefile
@@ -131,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
130
  version: '0'
132
131
  requirements: []
133
132
  rubyforge_project:
134
- rubygems_version: 2.0.3
133
+ rubygems_version: 2.0.6
135
134
  signing_key:
136
135
  specification_version: 4
137
136
  summary: A WS-Federation + WS-Trust strategy for OmniAuth.
data/Gemfile.lock DELETED
@@ -1,37 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- omniauth-wsfed (0.2.1)
5
- omniauth (~> 1.1.0)
6
- xmlcanonicalizer (= 0.1.1)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- diff-lcs (1.1.3)
12
- hashie (1.2.0)
13
- omniauth (1.1.0)
14
- hashie (~> 1.2)
15
- rack
16
- rack (1.4.1)
17
- rack-test (0.6.2)
18
- rack (>= 1.0)
19
- rake (10.0.3)
20
- rspec (2.12.0)
21
- rspec-core (~> 2.12.0)
22
- rspec-expectations (~> 2.12.0)
23
- rspec-mocks (~> 2.12.0)
24
- rspec-core (2.12.2)
25
- rspec-expectations (2.12.1)
26
- diff-lcs (~> 1.1.3)
27
- rspec-mocks (2.12.1)
28
- xmlcanonicalizer (0.1.1)
29
-
30
- PLATFORMS
31
- ruby
32
-
33
- DEPENDENCIES
34
- omniauth-wsfed!
35
- rack-test (>= 0.6.2)
36
- rake (>= 10.0.3)
37
- rspec (>= 2.12.0)