Commit b960ac10 authored by Lukas Matt's avatar Lukas Matt

Use new webfinger discovery method

parent d3cb1bd4
...@@ -19,17 +19,19 @@ package federation ...@@ -19,17 +19,19 @@ package federation
import ( import (
"encoding/xml" "encoding/xml"
"strings" "fmt"
"errors" "errors"
) )
type WebFinger struct { type WebFinger struct {
Host string Host string
Handle string Handle string
Xrd WebfingerXml Json WebfingerJson
} }
// TODO XML webfinger is deprecated // TODO XML webfinger is deprecated but
// still used in host-meta which is required
// for a successful pod-active check
type WebfingerXml struct { type WebfingerXml struct {
XMLName xml.Name `xml:"XRD"` XMLName xml.Name `xml:"XRD"`
Xmlns string `xml:"xmlns,attr"` Xmlns string `xml:"xmlns,attr"`
...@@ -60,24 +62,14 @@ type WebfingerJsonLink struct { ...@@ -60,24 +62,14 @@ type WebfingerJsonLink struct {
} }
func (w *WebFinger) Discovery() error { func (w *WebFinger) Discovery() error {
err := FetchXml("GET", w.Host + "/.well-known/host-meta", nil, &w.Xrd) url := fmt.Sprintf("%s/.well-known/webfinger?resource=acct:%s", w.Host, w.Handle)
err := FetchJson("GET", url, nil, &w.Json)
if err != nil { if err != nil {
return err return err
} }
if len(w.Xrd.Links) < 1 { if len(w.Json.Links) < 1 {
return errors.New("XRD Link missing") return errors.New("Webfinger Links missing")
} }
return nil
for _, link := range w.Xrd.Links {
if link.Rel == "lrdd" && link.Template != "" {
err = FetchXml("GET", strings.Replace(
link.Template, "{uri}", "acct:" + w.Handle, 1), nil, &w.Xrd)
if err != nil {
return err
}
return nil
}
}
return errors.New("No lrdd rel found in webfinger document!")
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment