class OpenID::OpenIDServiceEndpoint
Constants
- OPENID_TYPE_URIS
OpenID service type URIs, listed in order of preference. The ordering of this list affects yadis and XRI service discovery.
Attributes
canonical_id[RW]
For XRI, the persistent identifier.
claimed_id[RW]
the verified identifier.
local_id[RW]
server_url[RW]
type_uris[RW]
used_yadis[RW]
Public Class Methods
from_basic_service_endpoint(endpoint)
click to toggle source
# File lib/openid/consumer/discovery.rb, line 157 def self.from_basic_service_endpoint(endpoint) # Create a new instance of this class from the endpoint object # passed in. # # @return: nil or OpenIDServiceEndpoint for this endpoint object""" type_uris = endpoint.match_types(OPENID_TYPE_URIS) # If any Type URIs match and there is an endpoint URI specified, # then this is an OpenID endpoint if (!type_uris.nil? and !type_uris.empty?) and !endpoint.uri.nil? openid_endpoint = self.new openid_endpoint.parse_service( endpoint.yadis_url, endpoint.uri, endpoint.type_uris, endpoint.service_element) else openid_endpoint = nil end return openid_endpoint end
from_discovery_result(discoveryResult)
click to toggle source
# File lib/openid/consumer/discovery.rb, line 223 def self.from_discovery_result(discoveryResult) # Create endpoints from a DiscoveryResult. # # @type discoveryResult: L{DiscoveryResult} # # @rtype: list of L{OpenIDServiceEndpoint} # # @raises L{XRDSError}: When the XRDS does not parse. if discoveryResult.is_xrds() meth = self.method('from_xrds') else meth = self.method('from_html') end return meth.call(discoveryResult.normalized_uri, discoveryResult.response_text) end
from_html(uri, html)
click to toggle source
# File lib/openid/consumer/discovery.rb, line 181 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
from_op_endpoint_url(op_endpoint_url)
click to toggle source
# File lib/openid/consumer/discovery.rb, line 241 def self.from_op_endpoint_url(op_endpoint_url) # Construct an OP-Identifier OpenIDServiceEndpoint object for # a given OP Endpoint URL # # @param op_endpoint_url: The URL of the endpoint # @rtype: OpenIDServiceEndpoint service = self.new service.server_url = op_endpoint_url service.type_uris = [OPENID_IDP_2_0_TYPE] return service end
from_session_value(value)
click to toggle source
# File lib/openid/consumer/discovery.rb, line 147 def self.from_session_value(value) return value unless value.is_a?(Hash) self.new.tap do |endpoint| value.each do |name, val| endpoint.instance_variable_set(name, val) end end end
from_xrds(uri, xrds)
click to toggle source
# File lib/openid/consumer/discovery.rb, line 214 def self.from_xrds(uri, xrds) # Parse the given document as XRDS looking for OpenID services. # # @rtype: [OpenIDServiceEndpoint] # # @raises L{XRDSError}: When the XRDS does not parse. return Yadis::apply_filter(uri, xrds, self) end
new()
click to toggle source
# File lib/openid/consumer/discovery.rb, line 48 def initialize @claimed_id = nil @server_url = nil @type_uris = [] @local_id = nil @canonical_id = nil @used_yadis = false # whether this came from an XRDS @display_identifier = nil end
Public Instance Methods
==(other)
click to toggle source
# File lib/openid/consumer/discovery.rb, line 143 def ==(other) to_session_value == other.to_session_value end
compatibility_mode()
click to toggle source
# File lib/openid/consumer/discovery.rb, line 104 def compatibility_mode return preferred_namespace() != OPENID_2_0_MESSAGE_NS end
display_identifier()
click to toggle source
# File lib/openid/consumer/discovery.rb, line 58 def display_identifier return @display_identifier if @display_identifier return @claimed_id if @claimed_id.nil? begin parsed_identifier = URI.parse(@claimed_id) rescue URI::InvalidURIError raise ProtocolError, "Claimed identifier #{claimed_id} is not a valid URI" end return @claimed_id if not parsed_identifier.fragment disp = parsed_identifier disp.fragment = nil return disp.to_s end
display_identifier=(display_identifier)
click to toggle source
# File lib/openid/consumer/discovery.rb, line 77 def display_identifier=(display_identifier) @display_identifier = display_identifier end
get_local_id()
click to toggle source
# File lib/openid/consumer/discovery.rb, line 129 def get_local_id # Return the identifier that should be sent as the # openid.identity parameter to the server. if @local_id.nil? and @canonical_id.nil? return @claimed_id else return (@local_id or @canonical_id) end end
is_op_identifier()
click to toggle source
# File lib/openid/consumer/discovery.rb, line 108 def is_op_identifier return @type_uris.member?(OPENID_IDP_2_0_TYPE) end
parse_service(yadis_url, uri, type_uris, service_element)
click to toggle source
# File lib/openid/consumer/discovery.rb, line 112 def parse_service(yadis_url, uri, type_uris, service_element) # Set the state of this object based on the contents of the # service element. @type_uris = type_uris @server_url = uri @used_yadis = true if !is_op_identifier() # XXX: This has crappy implications for Service elements that # contain both 'server' and 'signon' Types. But that's a # pathological configuration anyway, so I don't think I care. @local_id = OpenID.find_op_local_identifier(service_element, @type_uris) @claimed_id = yadis_url end end
preferred_namespace()
click to toggle source
# File lib/openid/consumer/discovery.rb, line 85 def preferred_namespace if (@type_uris.member?(OPENID_IDP_2_0_TYPE) or @type_uris.member?(OPENID_2_0_TYPE)) return OPENID_2_0_MESSAGE_NS else return OPENID_1_0_MESSAGE_NS end end
supports_type(type_uri)
click to toggle source
# File lib/openid/consumer/discovery.rb, line 94 def supports_type(type_uri) # Does this endpoint support this type? # # I consider C{/server} endpoints to implicitly support C{/signon}. ( @type_uris.member?(type_uri) or (type_uri == OPENID_2_0_TYPE and is_op_identifier()) ) end
to_s()
click to toggle source
# File lib/openid/consumer/discovery.rb, line 253 def to_s return sprintf("<%s server_url=%s claimed_id=%s " + "local_id=%s canonical_id=%s used_yadis=%s>", self.class, @server_url, @claimed_id, @local_id, @canonical_id, @used_yadis) end
to_session_value()
click to toggle source
# File lib/openid/consumer/discovery.rb, line 139 def to_session_value Hash[*(instance_variables.map{|name| [name, instance_variable_get(name)] }.flatten(1))] end
uses_extension(extension_uri)
click to toggle source
# File lib/openid/consumer/discovery.rb, line 81 def uses_extension(extension_uri) return @type_uris.member?(extension_uri) end