Method: OpenID::OpenIDServiceEndpoint.from_html

Defined in:
lib/openid/consumer/discovery.rb

.from_html(uri, html) ⇒ Object



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/openid/consumer/discovery.rb', line 163

def self.from_html(uri, html)
  # Parse the given document as HTML looking for an OpenID <link
  # rel=...>
  #
  # @rtype: [OpenIDServiceEndpoint]

  discovery_types = [
                     [OPENID_2_0_TYPE, 'openid2.provider', 'openid2.local_id'],
                     [OPENID_1_1_TYPE, 'openid.server', 'openid.delegate'],
                    ]

  link_attrs = OpenID.parse_link_attrs(html)
  services = []
  discovery_types.each { |type_uri, op_endpoint_rel, local_id_rel|

    op_endpoint_url = OpenID.find_first_href(link_attrs, op_endpoint_rel)

    if !op_endpoint_url
      next
    end

    service = self.new
    service.claimed_id = uri
    service.local_id = OpenID.find_first_href(link_attrs, local_id_rel)
    service.server_url = op_endpoint_url
    service.type_uris = [type_uri]

    services << service
  }

  return services
end