- # This seems a better fit in Salmon
- def ensure_keys_present(user) do
- info = user.info || %{}
- if info["keys"] do
- {:ok, user}
+ defp get_magic_key(nil) do
+ Logger.debug("Undefined magic key.")
+ {:ok, nil}
+ end
+
+ defp get_magic_key(_) do
+ {:error, "Missing magic key data."}
+ end
+
+ defp webfinger_from_xml(doc) do
+ with magic_key <- XML.string_from_xpath(~s{//Link[@rel="magic-public-key"]/@href}, doc),
+ {:ok, magic_key} <- get_magic_key(magic_key),
+ topic <-
+ XML.string_from_xpath(
+ ~s{//Link[@rel="http://schemas.google.com/g/2010#updates-from"]/@href},
+ doc
+ ),
+ subject <- XML.string_from_xpath("//Subject", doc),
+ subscribe_address <-
+ XML.string_from_xpath(
+ ~s{//Link[@rel="http://ostatus.org/schema/1.0/subscribe"]/@template},
+ doc
+ ),
+ ap_id <-
+ XML.string_from_xpath(
+ ~s{//Link[@rel="self" and @type="application/activity+json"]/@href},
+ doc
+ ) do
+ data = %{
+ "magic_key" => magic_key,
+ "topic" => topic,
+ "subject" => subject,
+ "subscribe_address" => subscribe_address,
+ "ap_id" => ap_id
+ }
+
+ {:ok, data}