Class: OmniAuth::Strategies::WIND

Inherits:
Object
  • Object
show all
Includes:
OmniAuth::Strategy
Defined in:
lib/omni_auth/strategies/w_i_n_d.rb,
lib/omni_auth/strategies/w_i_n_d/logout_request.rb,
lib/omni_auth/strategies/w_i_n_d/service_ticket_validator.rb

Defined Under Namespace

Classes: InvalidWINDTicket, LogoutRequest, MissingWINDTicket, ServiceTicketValidator

Constant Summary collapse

AuthHashSchemaKeys =
%w{name email nickname first_name last_name location}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#raw_infoObject Also known as: user_info

Returns the value of attribute raw_info.



18
19
20
# File 'lib/omni_auth/strategies/w_i_n_d.rb', line 18

def raw_info
  @raw_info
end

Instance Method Details

#append_params(base, params) ⇒ Object



156
157
158
159
160
161
# File 'lib/omni_auth/strategies/w_i_n_d.rb', line 156

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

#callback_phaseObject



124
125
126
127
128
129
130
131
132
133
134
# File 'lib/omni_auth/strategies/w_i_n_d.rb', line 124

def callback_phase
  if on_sso_path?
    single_sign_out_phase
  else
    @ticket = request.params['ticketid']
    return fail!(:no_ticket, MissingWINDTicket.new('No WIND Ticket')) unless @ticket
    fetch_raw_info(@ticket)
    return fail!(:invalid_ticket, InvalidWINDTicket.new('Invalid WIND Ticket')) if raw_info.empty?
    super
  end
end

#extract_urlObject



99
100
101
102
103
104
105
106
107
# File 'lib/omni_auth/strategies/w_i_n_d.rb', line 99

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

#login_url(service) ⇒ Object



77
78
79
# File 'lib/omni_auth/strategies/w_i_n_d.rb', line 77

def (service)
  wind_url + append_params(options., { destination: service, service: options.service })
end

#logout_url(service) ⇒ Object



80
81
82
# File 'lib/omni_auth/strategies/w_i_n_d.rb', line 80

def logout_url(service)
  wind_url + append_params(options.logout_url, { destination: service})
end

#on_sso_path?Boolean

Returns:

  • (Boolean)


148
149
150
# File 'lib/omni_auth/strategies/w_i_n_d.rb', line 148

def on_sso_path?
  request.post? && request.params.has_key?('logoutRequest')
end

#request_phaseObject



135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/omni_auth/strategies/w_i_n_d.rb', line 135

def request_phase
  service_url = append_params(callback_url, return_url)

  [
    302,
    {
      'Location' => (service_url),
      'Content-Type' => 'text/plain'
    },
    ["You are being redirected to WIND for sign-in."]
  ]
end

#service_validate_url(service_url, ticket) ⇒ Object



115
116
117
118
119
120
121
122
# File 'lib/omni_auth/strategies/w_i_n_d.rb', line 115

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('ticketid') }
  r = wind_url + append_params(options.service_validate_url, {
    ticketid: ticket
  })
  r
end

#single_sign_out_phaseObject



152
153
154
# File 'lib/omni_auth/strategies/w_i_n_d.rb', line 152

def single_sign_out_phase
  logout_request_service.new(self, request).call(options)
end

#validate_service_ticket(ticket) ⇒ Object

Validate the Service Ticket

Returns:

  • (Object)

    the validated Service Ticket



165
166
167
# File 'lib/omni_auth/strategies/w_i_n_d.rb', line 165

def validate_service_ticket(ticket)
  OmniAuth::Strategies::WIND::ServiceTicketValidator.new(self, options, callback_url, ticket).call
end

#validate_wind_setupObject



109
110
111
112
113
# File 'lib/omni_auth/strategies/w_i_n_d.rb', line 109

def validate_wind_setup
  if options.host.nil? || options..nil?
    raise ArgumentError.new(":host and :login_url MUST be provided")
  end
end

#wind_urlObject

Build a WIND host with protocol and port



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/omni_auth/strategies/w_i_n_d.rb', line 86

def wind_url
  extract_url if options['url']
  validate_wind_setup
  @wind_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