Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Adds support for CAS servers that are mounted within another applicat…

…ion via a nested route

For instance: https://mycompany.com/stuff/cas
  • Loading branch information...
commit 9d8a1369147f94867876b0f707d7b250adfb2cbc 1 parent d57b045
Derek Lindahl authored February 26, 2013
21  lib/omniauth/strategies/cas.rb
@@ -20,6 +20,7 @@ class InvalidCASTicket < StandardError; end
20 20
 
21 21
       option :host, nil
22 22
       option :port, nil
  23
+      option :path, nil
23 24
       option :ssl,  true
24 25
       option :service_validate_url, '/serviceValidate'
25 26
       option :login_url,            '/login'
@@ -87,12 +88,15 @@ def request_phase
87 88
       # Build a CAS host with protocol and port
88 89
       #
89 90
       #
90  
-      def cas_host
91  
-        @host ||= begin
92  
-          host = @options.ssl ? "https" : "http"
93  
-          port = @options.port ? ":#{@options.port}" : ''
94  
-
95  
-          "#{host}://#{@options.host}#{port}"
  91
+      def cas_url
  92
+        @cas_url ||= begin
  93
+          uri = Addressable::URI.new
  94
+          uri.host   = @options.host
  95
+          uri.scheme = @options.ssl ? 'https' : 'http'
  96
+          uri.port   = @options.post
  97
+          uri.path   = @options.path
  98
+
  99
+          uri.to_s
96 100
         end
97 101
       end
98 102
 
@@ -109,8 +113,7 @@ def service_validate_url(service_url, ticket)
109 113
         service_url = Addressable::URI.parse( service_url )
110 114
         service_url.query_values = service_url.query_values.tap { |qs| qs.delete('ticket') }
111 115
 
112  
-        # cas_host + append_params(@options.service_validate_url, { :service => service_url.to_s, :ticket => ticket })
113  
-        cas_host + append_params(@options.service_validate_url, { :service => service_url.to_s, :ticket => ticket })
  116
+        cas_url + append_params(@options.service_validate_url, { :service => service_url.to_s, :ticket => ticket })
114 117
       end
115 118
 
116 119
       # Build a CAS login URL from +service+.
@@ -119,7 +122,7 @@ def service_validate_url(service_url, ticket)
119 122
       #
120 123
       # @return [String] a URL like `http://cas.mycompany.com/login?service=...`
121 124
       def login_url(service)
122  
-        cas_host + append_params( @options.login_url, { :service => service })
  125
+        cas_url + append_params( @options.login_url, { :service => service })
123 126
       end
124 127
 
125 128
       # Adds URL-escaped +parameters+ to +base+.
1  lib/omniauth/strategies/cas/configuration.rb
@@ -17,6 +17,7 @@ def extract_url
17 17
           @options.merge!(
18 18
             'host' => url.host,
19 19
             'port' => url.port,
  20
+            'path' => url.path,
20 21
             'ssl'  => url.scheme == 'https'
21 22
           )
22 23
         end
3  spec/omniauth/strategies/cas/configuration_spec.rb
@@ -13,7 +13,7 @@
13 13
   describe '#initialize' do
14 14
     let(:params) do
15 15
       {
16  
-        'url'       => 'http://example.org:8080',
  16
+        'url'       => 'http://example.org:8080/my_cas',
17 17
         'login_url' => '/'
18 18
       }
19 19
     end
@@ -31,6 +31,7 @@
31 31
       it 'should parse the URL' do
32 32
         subject.host.should eq 'example.org'
33 33
         subject.port.should eq 8080
  34
+        subject.path.should eq '/my_cas'
34 35
         subject.ssl.should  be_false
35 36
       end
36 37
     end

0 notes on commit 9d8a136

Please sign in to comment.
Something went wrong with that request. Please try again.