Class: DiasporaFederation::Discovery::WebFinger

Inherits:
Entity
  • Object
show all
Defined in:
lib/diaspora_federation/discovery/web_finger.rb

Overview

The WebFinger document used for diaspora* user discovery is based on an older draft of the specification.

In the meantime an actual RFC draft has been in development, which should serve as a base for all future changes of this implementation.

Examples:

Creating a WebFinger document from a person hash

wf = WebFinger.new(
  acct_uri:    "acct:[email protected]",
  alias_url:   "https://server.example/people/0123456789abcdef",
  hcard_url:   "https://server.example/hcard/users/user",
  seed_url:    "https://server.example/",
  profile_url: "https://server.example/u/user",
  atom_url:    "https://server.example/public/user.atom",
  salmon_url:  "https://server.example/receive/users/0123456789abcdef",
  guid:        "0123456789abcdef",
  public_key:  "-----BEGIN PUBLIC KEY-----\nABCDEF==\n-----END PUBLIC KEY-----"
)
xml_string = wf.to_xml

Creating a WebFinger instance from an xml document

wf = WebFinger.from_xml(xml_string)
...
hcard_url = wf.hcard_url
...

See Also:

Constant Summary collapse

REL_HCARD =

hcard_url link relation

"http://microformats.org/profile/hcard".freeze
REL_SEED =

seed_url link relation

"http://joindiaspora.com/seed_location".freeze
REL_GUID =
Deprecated.

This should be a Property or moved to the hCard, but Link is inappropriate according to the specification (will affect older diaspora* installations).

guid link relation

"http://joindiaspora.com/guid".freeze
REL_PROFILE =
Note:

This might just as well be an Alias instead of a Link.

profile_url link relation.

"http://webfinger.net/rel/profile-page".freeze
REL_ATOM =

atom_url link relation

"http://schemas.google.com/g/2010#updates-from".freeze
REL_SALMON =

salmon_url link relation

"salmon".freeze
REL_SUBSCRIBE =

subscribe_url link relation

"http://ostatus.org/schema/1.0/subscribe".freeze
REL_PUBKEY =
Deprecated.

This should be a Property or moved to the hcard, but Link is inappropriate according to the specification (will affect older diaspora* installations).

pubkey link relation

"diaspora-public-key".freeze

Constants inherited from Entity

Entity::INVALID_XML_REGEX

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Entity

entity_class, entity_name, #initialize, #to_h

Methods included from PropertiesDSL

#class_props, #default_values, #entity, #find_property_for_xml_name, #missing_props, #property, #resolv_aliases, #xml_names

Methods included from Logging

included

Constructor Details

This class inherits a constructor from DiasporaFederation::Entity

Instance Attribute Details

#acct_uriString (readonly)

The Subject element should contain the webfinger address that was asked for. If it does not, then this webfinger profile MUST be ignored.

Returns:

  • (String)


38
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 38

property :acct_uri

#alias_urlString (readonly)

Note:

could be nil

Returns link to the users profile.

Returns:

  • (String)

    link to the users profile



43
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 43

property :alias_url

#atom_urlString (readonly)

This atom feed is an Activity Stream of the user’s public posts. diaspora* pods SHOULD publish an Activity Stream of public posts, but there is currently no requirement to be able to read Activity Streams. Note that this feed MAY also be made available through the PubSubHubbub mechanism by supplying a <link rel=“hub”> in the atom feed itself.

Returns:

  • (String)

    atom feed url

See Also:



66
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 66

property :atom_url

#guidString (readonly)

Deprecated.

Either convert these to Property elements or move to the hCard, which actually has fields for an UID defined in the vCard specification (will affect older diaspora* installations).

Returns guid.

Returns:

  • (String)

    guid

See Also:



87
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 87

property :guid

#hcard_urlString (readonly)

Returns link to the hCard.

Returns:

  • (String)

    link to the hCard



47
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 47

property :hcard_url

#profile_urlString (readonly)

Returns link to the users profile.

Returns:

  • (String)

    link to the users profile



55
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 55

property :profile_url

#public_keyString (readonly)

Deprecated.

Either convert these to Property elements or move to the hCard, which actually has fields for an KEY defined in the vCard specification (will affect older diaspora* installations).

When a user is created on the pod, the pod MUST generate a pgp keypair for them. This key is used for signing messages. The format is a DER-encoded PKCS#1 key beginning with the text “—–BEGIN PUBLIC KEY—–” and ending with “—–END PUBLIC KEY—–”.

Returns:

  • (String)

    public key

See Also:



101
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 101

property :public_key

#salmon_urlString (readonly)

Note:

could be nil

Returns salmon endpoint url.

Returns:

  • (String)

    salmon endpoint url

See Also:



73
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 73

property :salmon_url

#seed_urlString (readonly)

Returns link to the pod.

Returns:

  • (String)

    link to the pod



51
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 51

property :seed_url

#subscribe_urlObject (readonly)

This url is used to find another user on the home-pod of the user in the webfinger.



77
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 77

property :subscribe_url

Class Method Details

.from_xml(webfinger_xml) ⇒ WebFinger

Creates a WebFinger instance from the given XML string

Parameters:

  • webfinger_xml (String)

    WebFinger XML string

Returns:

Raises:

  • (InvalidData)

    if the given XML string is invalid or incomplete



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 150

def self.from_xml(webfinger_xml)
  data = parse_xml_and_validate(webfinger_xml)

  links = data[:links]

  # TODO: remove! public key is deprecated in webfinger
  public_key = parse_link(links, REL_PUBKEY)

  new(
    acct_uri:      data[:subject],
    alias_url:     parse_alias(data[:aliases]),
    hcard_url:     parse_link(links, REL_HCARD),
    seed_url:      parse_link(links, REL_SEED),
    profile_url:   parse_link(links, REL_PROFILE),
    atom_url:      parse_link(links, REL_ATOM),
    salmon_url:    parse_link(links, REL_SALMON),

    subscribe_url: parse_link_template(links, REL_SUBSCRIBE),

    # TODO: remove me!  ##########
    guid:          parse_link(links, REL_GUID),
    public_key:    (Base64.strict_decode64(public_key) if public_key)
  )
end

Instance Method Details

#to_sString

Returns string representation of this object.

Returns:

  • (String)

    string representation of this object



176
177
178
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 176

def to_s
  "WebFinger:#{acct_uri}"
end

#to_xmlString

Creates the XML string from the current WebFinger instance

Returns:

  • (String)

    XML string



136
137
138
139
140
141
142
143
144
# File 'lib/diaspora_federation/discovery/web_finger.rb', line 136

def to_xml
  doc = XrdDocument.new
  doc.subject = @acct_uri
  doc.aliases << @alias_url

  add_links_to(doc)

  doc.to_xml
end