Class: OpenID::OpenIDServiceEndpoint
- Inherits:
-
Object
- Object
- OpenID::OpenIDServiceEndpoint
- Defined in:
- lib/openid/consumer/discovery.rb
Overview
Object representing an OpenID service endpoint.
Constant Summary collapse
- OPENID_TYPE_URIS =
OpenID service type URIs, listed in order of preference. The ordering of this list affects yadis and XRI service discovery.
[ OPENID_IDP_2_0_TYPE, OPENID_2_0_TYPE, OPENID_1_1_TYPE, OPENID_1_0_TYPE, ]
Instance Attribute Summary collapse
-
#canonical_id ⇒ Object
For XRI, the persistent identifier.
-
#claimed_id ⇒ Object
the verified identifier.
-
#local_id ⇒ Object
Returns the value of attribute local_id.
-
#server_url ⇒ Object
Returns the value of attribute server_url.
-
#type_uris ⇒ Object
Returns the value of attribute type_uris.
-
#used_yadis ⇒ Object
Returns the value of attribute used_yadis.
Class Method Summary collapse
- .from_basic_service_endpoint(endpoint) ⇒ Object
- .from_discovery_result(discoveryResult) ⇒ Object
- .from_html(uri, html) ⇒ Object
- .from_op_endpoint_url(op_endpoint_url) ⇒ Object
- .from_xrds(uri, xrds) ⇒ Object
Instance Method Summary collapse
- #compatibility_mode ⇒ Object
- #display_identifier ⇒ Object
- #display_identifier=(display_identifier) ⇒ Object
- #get_local_id ⇒ Object
-
#initialize ⇒ OpenIDServiceEndpoint
constructor
A new instance of OpenIDServiceEndpoint.
- #is_op_identifier ⇒ Object
- #parse_service(yadis_url, uri, type_uris, service_element) ⇒ Object
- #preferred_namespace ⇒ Object
- #supports_type(type_uri) ⇒ Object
- #to_s ⇒ Object
- #uses_extension(extension_uri) ⇒ Object
Constructor Details
#initialize ⇒ OpenIDServiceEndpoint
Returns a new instance of OpenIDServiceEndpoint.
48 49 50 51 52 53 54 55 56 |
# 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 |
Instance Attribute Details
#canonical_id ⇒ Object
For XRI, the persistent identifier.
44 45 46 |
# File 'lib/openid/consumer/discovery.rb', line 44 def canonical_id @canonical_id end |
#claimed_id ⇒ Object
the verified identifier.
41 42 43 |
# File 'lib/openid/consumer/discovery.rb', line 41 def claimed_id @claimed_id end |
#local_id ⇒ Object
Returns the value of attribute local_id.
46 47 48 |
# File 'lib/openid/consumer/discovery.rb', line 46 def local_id @local_id end |
#server_url ⇒ Object
Returns the value of attribute server_url.
46 47 48 |
# File 'lib/openid/consumer/discovery.rb', line 46 def server_url @server_url end |
#type_uris ⇒ Object
Returns the value of attribute type_uris.
46 47 48 |
# File 'lib/openid/consumer/discovery.rb', line 46 def type_uris @type_uris end |
#used_yadis ⇒ Object
Returns the value of attribute used_yadis.
46 47 48 |
# File 'lib/openid/consumer/discovery.rb', line 46 def used_yadis @used_yadis end |
Class Method Details
.from_basic_service_endpoint(endpoint) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/openid/consumer/discovery.rb', line 139 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) ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/openid/consumer/discovery.rb', line 205 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) ⇒ 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 |
.from_op_endpoint_url(op_endpoint_url) ⇒ Object
223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/openid/consumer/discovery.rb', line 223 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_xrds(uri, xrds) ⇒ Object
196 197 198 199 200 201 202 203 |
# File 'lib/openid/consumer/discovery.rb', line 196 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 |
Instance Method Details
#compatibility_mode ⇒ Object
104 105 106 |
# File 'lib/openid/consumer/discovery.rb', line 104 def compatibility_mode return preferred_namespace() != OPENID_2_0_MESSAGE_NS end |
#display_identifier ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# 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) ⇒ Object
77 78 79 |
# File 'lib/openid/consumer/discovery.rb', line 77 def display_identifier=(display_identifier) @display_identifier = display_identifier end |
#get_local_id ⇒ Object
129 130 131 132 133 134 135 136 137 |
# 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 ⇒ Object
108 109 110 |
# 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) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# 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 ⇒ Object
85 86 87 88 89 90 91 92 |
# 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) ⇒ Object
94 95 96 97 98 99 100 101 102 |
# 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 ⇒ Object
235 236 237 238 239 240 |
# File 'lib/openid/consumer/discovery.rb', line 235 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 |
#uses_extension(extension_uri) ⇒ Object
81 82 83 |
# File 'lib/openid/consumer/discovery.rb', line 81 def uses_extension(extension_uri) return @type_uris.member?(extension_uri) end |