class OmniAuth::Strategies::CAS3
Constants
- AuthHashSchemaKeys
As required by github.com/intridea/omniauth/wiki/Auth-Hash-Schema
Attributes
Public Instance Methods
Adds URL-escaped parameters
to base
.
@param [String] base the base URL @param [String] params the parameters to append to the URL
@return [String] the new joined URL.
# File lib/omniauth/strategies/cas3.rb, line 176 def append_params(base, params) params = params.each { |k,v| v = Rack::Utils.escape(v) } Addressable::URI.parse(base).tap do |base_uri| base_uri.query_values = (base_uri.query_values || {}).merge(params) end.to_s end
# File lib/omniauth/strategies/cas3.rb, line 78 def callback_phase if on_sso_path? single_sign_out_phase else @ticket = request.params['ticket'] return fail!(:no_ticket, MissingCASTicket.new('No CAS Ticket')) unless @ticket fetch_raw_info(@ticket) return fail!(:invalid_ticket, InvalidCASTicket.new('Invalid CAS Ticket')) if raw_info.empty? super end end
Build a CAS host with protocol and port
# File lib/omniauth/strategies/cas3.rb, line 114 def cas_url extract_url if options['url'] validate_cas_setup @cas_url ||= begin uri = Addressable::URI.new uri.host = options.host uri.scheme = options.ssl ? 'https' : 'http' uri.port = options.port uri.path = options.path uri.to_s end end
# File lib/omniauth/strategies/cas3.rb, line 127 def extract_url url = Addressable::URI.parse(options.delete('url')) options.merge!( 'host' => url.host, 'port' => url.port, 'path' => url.path, 'ssl' => url.scheme == 'https' ) end
Build a CAS login URL from service
.
@param [String] service the service (a.k.a. return-to) URL
@return [String] a URL like `cas.mycompany.com/login?service=…`
# File lib/omniauth/strategies/cas3.rb, line 166 def login_url(service) cas_url + append_params(options.login_url, { service: service }) end
# File lib/omniauth/strategies/cas3.rb, line 103 def on_sso_path? request.post? && request.params.has_key?('logoutRequest') end
# File lib/omniauth/strategies/cas3.rb, line 90 def request_phase service_url = append_params(callback_url, return_url) [ 302, { 'Location' => login_url(service_url), 'Content-Type' => 'text/plain' }, ["You are being redirected to CAS for sign-in."] ] end
Build a service-validation URL from service
and
ticket
. If service
has a ticket param, first
remove it. URL-encode service
and add it and the
ticket
as paraemters to the CAS serviceValidate URL.
@param [String] service the service (a.k.a. return-to) URL @param [String] ticket the ticket to validate
@return [String] a URL like `cas.mycompany.com/serviceValidate?service=…&ticket=…`
# File lib/omniauth/strategies/cas3.rb, line 152 def service_validate_url(service_url, ticket) service_url = Addressable::URI.parse(service_url) service_url.query_values = service_url.query_values.tap { |qs| qs.delete('ticket') } cas_url + append_params(options.service_validate_url, { service: service_url.to_s, ticket: ticket }) end
# File lib/omniauth/strategies/cas3.rb, line 107 def single_sign_out_phase logout_request_service.new(self, request).call(options) end
# File lib/omniauth/strategies/cas3.rb, line 137 def validate_cas_setup if options.host.nil? || options.login_url.nil? raise ArgumentError.new(":host and :login_url MUST be provided") end end
Validate the Service Ticket @return [Object] the validated Service Ticket
# File lib/omniauth/strategies/cas3.rb, line 185 def validate_service_ticket(ticket) ServiceTicketValidator.new(self, options, callback_url, ticket).call end
Private Instance Methods
# File lib/omniauth/strategies/cas3.rb, line 191 def fetch_raw_info(ticket) ticket_user_info = validate_service_ticket(ticket).user_info custom_user_info = options.fetch_raw_info.call(self, options, ticket, ticket_user_info) self.raw_info = ticket_user_info.merge(custom_user_info) end
# File lib/omniauth/strategies/cas3.rb, line 215 def logout_request_service LogoutRequest end
Deletes Hash pairs with `nil` values. From github.com/mkdynamic/omniauth-facebook/blob/972ed5e3456bcaed7df1f55efd7c05c216c8f48e/lib/omniauth/strategies/facebook.rb#L122-127
# File lib/omniauth/strategies/cas3.rb, line 199 def prune!(hash) hash.delete_if do |_, value| prune!(value) if value.is_a?(Hash) value.nil? || (value.respond_to?(:empty?) && value.empty?) end end
# File lib/omniauth/strategies/cas3.rb, line 206 def return_url # If the request already has a `url` parameter, then it will already be appended to the callback URL. if request.params && request.params['url'] {} else { url: request.referer } end end