add ostatus subscribe-url to webfinger

This commit is contained in:
Benjamin Neff 2015-12-27 21:54:20 +01:00
parent fb00b95c74
commit 7ed848c2f5
5 changed files with 70 additions and 50 deletions

View file

@ -75,6 +75,10 @@ module DiasporaFederation
# Panzer draft for Salmon, paragraph 3.3 # Panzer draft for Salmon, paragraph 3.3
property :salmon_url property :salmon_url
# @!attribute [r] subscribe_url
# This url is used to find another user on the home-pod of the user in the webfinger.
property :subscribe_url
# @!attribute [r] guid # @!attribute [r] guid
# @deprecated Either convert these to +Property+ elements or move to the # @deprecated Either convert these to +Property+ elements or move to the
# +hCard+, which actually has fields for an +UID+ defined in the +vCard+ # +hCard+, which actually has fields for an +UID+ defined in the +vCard+
@ -121,6 +125,9 @@ module DiasporaFederation
# +salmon_url+ link relation # +salmon_url+ link relation
REL_SALMON = "salmon" REL_SALMON = "salmon"
# +subscribe_url+ link relation
REL_SUBSCRIBE = "http://ostatus.org/schema/1.0/subscribe"
# @deprecated This should be a +Property+ or moved to the +hcard+, but +Link+ # @deprecated This should be a +Property+ or moved to the +hcard+, but +Link+
# is inappropriate according to the specification (will affect older # is inappropriate according to the specification (will affect older
# Diaspora* installations). # Diaspora* installations).
@ -152,17 +159,19 @@ module DiasporaFederation
public_key = parse_link(links, REL_PUBKEY) public_key = parse_link(links, REL_PUBKEY)
new( new(
acct_uri: data[:subject], acct_uri: data[:subject],
alias_url: parse_alias(data[:aliases]), alias_url: parse_alias(data[:aliases]),
hcard_url: parse_link(links, REL_HCARD), hcard_url: parse_link(links, REL_HCARD),
seed_url: parse_link(links, REL_SEED), seed_url: parse_link(links, REL_SEED),
profile_url: parse_link(links, REL_PROFILE), profile_url: parse_link(links, REL_PROFILE),
atom_url: parse_link(links, REL_ATOM), atom_url: parse_link(links, REL_ATOM),
salmon_url: parse_link(links, REL_SALMON), salmon_url: parse_link(links, REL_SALMON),
subscribe_url: parse_link_template(links, REL_SUBSCRIBE),
# TODO: remove me! ########## # TODO: remove me! ##########
guid: parse_link(links, REL_GUID), guid: parse_link(links, REL_GUID),
public_key: (Base64.strict_decode64(public_key) if public_key) public_key: (Base64.strict_decode64(public_key) if public_key)
) )
end end
@ -182,27 +191,18 @@ module DiasporaFederation
private_class_method :parse_xml_and_validate private_class_method :parse_xml_and_validate
def add_links_to(doc) def add_links_to(doc)
doc.links << {rel: REL_HCARD, doc.links << {rel: REL_HCARD, type: "text/html", href: @hcard_url}
type: "text/html", doc.links << {rel: REL_SEED, type: "text/html", href: @seed_url}
href: @hcard_url}
doc.links << {rel: REL_SEED,
type: "text/html",
href: @seed_url}
# TODO: remove me! ############## # TODO: remove me! ##############
doc.links << {rel: REL_GUID, doc.links << {rel: REL_GUID, type: "text/html", href: @guid}
type: "text/html",
href: @guid}
################################## ##################################
doc.links << {rel: REL_PROFILE, doc.links << {rel: REL_PROFILE, type: "text/html", href: @profile_url}
type: "text/html", doc.links << {rel: REL_ATOM, type: "application/atom+xml", href: @atom_url}
href: @profile_url} doc.links << {rel: REL_SALMON, href: @salmon_url}
doc.links << {rel: REL_ATOM,
type: "application/atom+xml", doc.links << {rel: REL_SUBSCRIBE, template: @subscribe_url}
href: @atom_url}
doc.links << {rel: REL_SALMON,
href: @salmon_url}
# TODO: remove me! ############## # TODO: remove me! ##############
doc.links << {rel: REL_PUBKEY, doc.links << {rel: REL_PUBKEY,
@ -211,12 +211,23 @@ module DiasporaFederation
################################## ##################################
end end
def self.find_link(links, rel)
links.find {|l| l[:rel] == rel }
end
private_class_method :find_link
def self.parse_link(links, rel) def self.parse_link(links, rel)
element = links.find {|l| l[:rel] == rel } element = find_link(links, rel)
element ? element[:href] : nil element ? element[:href] : nil
end end
private_class_method :parse_link private_class_method :parse_link
def self.parse_link_template(links, rel)
element = find_link(links, rel)
element ? element[:template] : nil
end
private_class_method :parse_link_template
# this method is used to parse the alias_url from the XML. # this method is used to parse the alias_url from the XML.
# * redmatrix has sometimes no alias, return nil # * redmatrix has sometimes no alias, return nil
# * old pods had quotes around the alias url, this can be removed later # * old pods had quotes around the alias url, this can be removed later

View file

@ -21,6 +21,7 @@ module DiasporaFederation
atom_url "http://localhost:3000/public/user.atom" atom_url "http://localhost:3000/public/user.atom"
salmon_url "http://localhost:3000/receive/users/0123456789abcdef" salmon_url "http://localhost:3000/receive/users/0123456789abcdef"
public_key public_key
subscribe_url "http://localhost:3000/people?q={uri}"
end end
factory :h_card, class: DiasporaFederation::Discovery::HCard do factory :h_card, class: DiasporaFederation::Discovery::HCard do

View file

@ -6,15 +6,16 @@ module DiasporaFederation
let(:data) { let(:data) {
{ {
acct_uri: "acct:#{person.diaspora_id}", acct_uri: "acct:#{person.diaspora_id}",
alias_url: person.alias_url, alias_url: person.alias_url,
hcard_url: person.hcard_url, hcard_url: person.hcard_url,
seed_url: person.url, seed_url: person.url,
profile_url: person.profile_url, profile_url: person.profile_url,
atom_url: person.atom_url, atom_url: person.atom_url,
salmon_url: person.salmon_url, salmon_url: person.salmon_url,
guid: person.guid, guid: person.guid,
public_key: person.serialized_public_key public_key: person.serialized_public_key,
subscribe_url: person.subscribe_url
} }
} }
@ -30,6 +31,7 @@ module DiasporaFederation
<Link rel="http://webfinger.net/rel/profile-page" type="text/html" href="#{person.profile_url}"/> <Link rel="http://webfinger.net/rel/profile-page" type="text/html" href="#{person.profile_url}"/>
<Link rel="http://schemas.google.com/g/2010#updates-from" type="application/atom+xml" href="#{person.atom_url}"/> <Link rel="http://schemas.google.com/g/2010#updates-from" type="application/atom+xml" href="#{person.atom_url}"/>
<Link rel="salmon" href="#{person.salmon_url}"/> <Link rel="salmon" href="#{person.salmon_url}"/>
<Link rel="http://ostatus.org/schema/1.0/subscribe" template="#{person.subscribe_url}"/>
<Link rel="diaspora-public-key" type="RSA" href="#{public_key_base64}"/> <Link rel="diaspora-public-key" type="RSA" href="#{public_key_base64}"/>
</XRD> </XRD>
XML XML
@ -54,6 +56,7 @@ XML
expect(wf.profile_url).to eq(person.profile_url) expect(wf.profile_url).to eq(person.profile_url)
expect(wf.atom_url).to eq(person.atom_url) expect(wf.atom_url).to eq(person.atom_url)
expect(wf.salmon_url).to eq(person.salmon_url) expect(wf.salmon_url).to eq(person.salmon_url)
expect(wf.subscribe_url).to eq(person.subscribe_url)
expect(wf.guid).to eq(person.guid) expect(wf.guid).to eq(person.guid)
expect(wf.public_key).to eq(person.serialized_public_key) expect(wf.public_key).to eq(person.serialized_public_key)
@ -150,6 +153,7 @@ XML
expect(wf.profile_url).to eq(person.profile_url) expect(wf.profile_url).to eq(person.profile_url)
expect(wf.atom_url).to eq(person.atom_url) expect(wf.atom_url).to eq(person.atom_url)
expect(wf.salmon_url).to eq(person.salmon_url) expect(wf.salmon_url).to eq(person.salmon_url)
expect(wf.subscribe_url).to eq("https://pod.example.tld/follow?url={uri}")
expect(wf.guid).to eq(person.guid) expect(wf.guid).to eq(person.guid)
expect(wf.public_key).to eq(person.serialized_public_key) expect(wf.public_key).to eq(person.serialized_public_key)
@ -211,6 +215,7 @@ XML
<Link rel="http://webfinger.net/rel/profile-page" type="text/html" href="#{person.profile_url}"/> <Link rel="http://webfinger.net/rel/profile-page" type="text/html" href="#{person.profile_url}"/>
<Link rel="http://schemas.google.com/g/2010#updates-from" type="application/atom+xml" href="#{person.atom_url}"/> <Link rel="http://schemas.google.com/g/2010#updates-from" type="application/atom+xml" href="#{person.atom_url}"/>
<Link rel="salmon" href="#{person.salmon_url}"/> <Link rel="salmon" href="#{person.salmon_url}"/>
<Link rel="http://ostatus.org/schema/1.0/subscribe" template="#{person.subscribe_url}"/>
</XRD> </XRD>
XML XML
@ -222,6 +227,7 @@ XML
expect(wf.profile_url).to eq(person.profile_url) expect(wf.profile_url).to eq(person.profile_url)
expect(wf.atom_url).to eq(person.atom_url) expect(wf.atom_url).to eq(person.atom_url)
expect(wf.salmon_url).to eq(person.salmon_url) expect(wf.salmon_url).to eq(person.salmon_url)
expect(wf.subscribe_url).to eq(person.subscribe_url)
expect(wf.guid).to be_nil expect(wf.guid).to be_nil
expect(wf.public_key).to be_nil expect(wf.public_key).to be_nil

View file

@ -1,11 +1,12 @@
class Person < ActiveRecord::Base class Person < ActiveRecord::Base
include ::Diaspora::Guid include ::Diaspora::Guid
def alias_url; "#{url}people/#{guid}" end def alias_url; "#{url}people/#{guid}" end
def hcard_url; "#{url}hcard/users/#{guid}" end def hcard_url; "#{url}hcard/users/#{guid}" end
def profile_url; "#{url}u/#{nickname}" end def profile_url; "#{url}u/#{nickname}" end
def atom_url; "#{url}public/#{nickname}.atom" end def atom_url; "#{url}public/#{nickname}.atom" end
def salmon_url; "#{url}receive/users/#{guid}" end def salmon_url; "#{url}receive/users/#{guid}" end
def subscribe_url; "#{url}people?q={uri}" end
def nickname; diaspora_id.split("@")[0] end def nickname; diaspora_id.split("@")[0] end

View file

@ -20,15 +20,16 @@ DiasporaFederation.configure do |config|
person = Person.find_by(diaspora_id: diaspora_id) person = Person.find_by(diaspora_id: diaspora_id)
if person if person
DiasporaFederation::Discovery::WebFinger.new( DiasporaFederation::Discovery::WebFinger.new(
acct_uri: "acct:#{person.diaspora_id}", acct_uri: "acct:#{person.diaspora_id}",
alias_url: person.alias_url, alias_url: person.alias_url,
hcard_url: person.hcard_url, hcard_url: person.hcard_url,
seed_url: person.url, seed_url: person.url,
profile_url: person.profile_url, profile_url: person.profile_url,
atom_url: person.atom_url, atom_url: person.atom_url,
salmon_url: person.salmon_url, salmon_url: person.salmon_url,
guid: person.guid, subscribe_url: person.subscribe_url,
public_key: person.serialized_public_key guid: person.guid,
public_key: person.serialized_public_key
) )
end end
end end