Class: OmniAuth::Strategies::CAS
- Inherits:
-
Object
- Object
- OmniAuth::Strategies::CAS
- Includes:
- OmniAuth::Strategy
- Defined in:
- lib/omniauth/strategies/cas.rb,
lib/omniauth/strategies/cas/logout_request.rb,
lib/omniauth/strategies/cas/service_ticket_validator.rb
Defined Under Namespace
Classes: InvalidCASTicket, LogoutRequest, MissingCASTicket, ServiceTicketValidator
Constant Summary collapse
- AUTH_HASH_SCHEMA_KEYS =
As required by https://github.com/intridea/omniauth/wiki/Auth-Hash-Schema
%w[name email nickname first_name last_name location image phone].freeze
Instance Attribute Summary collapse
-
#raw_info ⇒ Object
(also: #user_info)
Returns the value of attribute raw_info.
Instance Method Summary collapse
-
#append_params(base, params) ⇒ String
Adds URL-escaped
parameterstobase. - #callback_phase ⇒ Object
-
#cas_url ⇒ Object
Build a CAS host with protocol and port.
- #extract_url ⇒ Object
-
#login_url(service) ⇒ String
Build a CAS login URL from
service. - #on_sso_path? ⇒ Boolean
- #request_phase ⇒ Object
-
#service_validate_url(service_url, ticket) ⇒ String
Build a service-validation URL from
serviceandticket. - #single_sign_out_phase ⇒ Object
- #validate_cas_setup ⇒ Object
-
#validate_service_ticket(ticket) ⇒ Object
Validate the Service Ticket.
Instance Attribute Details
#raw_info ⇒ Object Also known as: user_info
Returns the value of attribute raw_info.
18 19 20 |
# File 'lib/omniauth/strategies/cas.rb', line 18 def raw_info @raw_info end |
Instance Method Details
#append_params(base, params) ⇒ String
Adds URL-escaped parameters to base.
183 184 185 186 187 188 |
# File 'lib/omniauth/strategies/cas.rb', line 183 def append_params(base, params) params = params.each_value { |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 |
#callback_phase ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/omniauth/strategies/cas.rb', line 83 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 |
#cas_url ⇒ Object
Build a CAS host with protocol and port
121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/omniauth/strategies/cas.rb', line 121 def cas_url extract_url if ['url'] validate_cas_setup @cas_url ||= begin uri = Addressable::URI.new uri.host = .host uri.scheme = .ssl ? 'https' : 'http' uri.port = .port uri.path = .path uri.to_s end end |
#extract_url ⇒ Object
134 135 136 137 138 139 140 141 142 |
# File 'lib/omniauth/strategies/cas.rb', line 134 def extract_url url = Addressable::URI.parse(.delete('url')) .merge!( 'host' => url.host, 'port' => url.port, 'path' => url.path, 'ssl' => url.scheme == 'https' ) end |
#login_url(service) ⇒ String
Build a CAS login URL from service.
173 174 175 |
# File 'lib/omniauth/strategies/cas.rb', line 173 def login_url(service) cas_url + append_params(.login_url, { service: service }) end |
#on_sso_path? ⇒ Boolean
110 111 112 |
# File 'lib/omniauth/strategies/cas.rb', line 110 def on_sso_path? request.post? && request.params.key?('logoutRequest') end |
#request_phase ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/omniauth/strategies/cas.rb', line 97 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 |
#service_validate_url(service_url, ticket) ⇒ String
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.
159 160 161 162 163 164 165 166 |
# File 'lib/omniauth/strategies/cas.rb', line 159 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(.service_validate_url, { service: service_url.to_s, ticket: ticket }) end |
#single_sign_out_phase ⇒ Object
114 115 116 |
# File 'lib/omniauth/strategies/cas.rb', line 114 def single_sign_out_phase logout_request_service.new(self, request).call() end |
#validate_cas_setup ⇒ Object
144 145 146 147 148 |
# File 'lib/omniauth/strategies/cas.rb', line 144 def validate_cas_setup return unless .host.nil? || .login_url.nil? raise ArgumentError, ':host and :login_url MUST be provided' end |
#validate_service_ticket(ticket) ⇒ Object
Validate the Service Ticket
192 193 194 |
# File 'lib/omniauth/strategies/cas.rb', line 192 def validate_service_ticket(ticket) ServiceTicketValidator.new(self, , callback_url, ticket).call end |