Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to configure extra URL parameters for the validate_service URL #95

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,15 @@ The CAS standard allows for a `renew=true` parameter to be passed to the CAS ser
config.rack_cas.renew = true
```

Extra query parameters to serviceValidate
-----------------------------------------

Some CAS servers needs extra query parameters to be passed to serviceValidate. These can be configured by adding the following to `config/application.rb`:

```ruby
config.rack_cas.extra_params_validate = { key: 'verysecret', location: 'here' }
```

Integration
===========
Your app should __return a [401 status](http://httpstatus.es/401)__ whenever a request is made that requires authentication. Rack-CAS will catch these responses and attempt to authenticate via your CAS server.
Expand Down
3 changes: 2 additions & 1 deletion lib/rack-cas/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module RackCAS
class Configuration
SETTINGS = [:fake, :fake_attributes, :server_url, :session_store, :exclude_path, :exclude_paths, :extra_attributes_filter,
:verify_ssl_cert, :renew, :use_saml_validation, :ignore_intercept_validator, :exclude_request_validator, :protocol,
:redis_options, :login_url, :service]
:redis_options, :login_url, :service, :extra_params_validate]


SETTINGS.each do |setting|
Expand All @@ -15,6 +15,7 @@ class Configuration

def initialize
@verify_ssl_cert = true
@extra_params_validate = {}
end

def extra_attributes_filter
Expand Down
17 changes: 10 additions & 7 deletions lib/rack-cas/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,28 @@ def logout_url(params = {})
end
end

def validate_service(service_url, ticket)
def validate_service(service_url, ticket, params = {})
params = RackCAS.config.extra_params_validate
unless RackCAS.config.use_saml_validation?
response = ServiceValidationResponse.new validate_service_url(service_url, ticket)
response = ServiceValidationResponse.new validate_service_url(service_url, ticket, params)
else
response = SAMLValidationResponse.new saml_validate_url(service_url), ticket
response = SAMLValidationResponse.new saml_validate_url(service_url, params), ticket
end
[response.user, response.extra_attributes]
end

protected

def saml_validate_url(service_url)
def saml_validate_url(service_url, params = {})
service_url = URL.parse(service_url).remove_param('ticket').to_s
@url.dup.append_path(path_for_protocol('samlValidate')).add_params(TARGET: service_url)
base_params = {TARGET: service_url}
@url.dup.append_path(path_for_protocol('samlValidate')).add_params(base_params.merge(params))
end

def validate_service_url(service_url, ticket)
def validate_service_url(service_url, ticket, params = {})
service_url = URL.parse(service_url).remove_param('ticket').to_s
@url.dup.append_path(path_for_protocol('serviceValidate')).add_params(service: service_url, ticket: ticket)
base_params = {service: service_url, ticket: ticket}
@url.dup.append_path(path_for_protocol('serviceValidate')).add_params(base_params.merge(params))
end

def path_for_protocol(path)
Expand Down
2 changes: 1 addition & 1 deletion spec/rack-cas/cas_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def app
end

context 'single sign out request' do
before { post "/?logoutRequest=#{URI.encode(fixture('single_sign_out_request.xml'))}" }
before { post "/?logoutRequest=#{URI::Parser.new.escape(fixture('single_sign_out_request.xml'))}" }
its(:ticket) { should eql 'ST-0123456789ABCDEFGHIJKLMNOPQRS' }
its(:single_sign_out?) { should be true }
its(:logout?) { should be false }
Expand Down
2 changes: 1 addition & 1 deletion spec/rack/cas_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def app
{ session_store: session_store }
}

subject { post "/?logoutRequest=#{URI.encode(fixture('single_sign_out_request.xml'))}" }
subject { post "/?logoutRequest=#{URI::Parser.new.escape(fixture('single_sign_out_request.xml'))}" }
its(:status) { should eql 200 }
its(:body) { should eql 'CAS Single-Sign-Out request intercepted.' }
end
Expand Down