Commit 9fe13ba2 authored by zauberstuhl's avatar zauberstuhl
Browse files

Fix static webfinger link

parent 8cf9d860
# GangGo Federation Library # GangGo Federation Library
Pretty raw federation library for golang to communicate with the diaspora protocol Federation library for golang to communicate with the diaspora protocol
## Dependencies
For parsing hcard's the library requires a third party lib:
github.com/PuerkitoBio/goquery
...@@ -32,4 +32,8 @@ const ( ...@@ -32,4 +32,8 @@ const (
Comment = "comment" Comment = "comment"
Like = "like" Like = "like"
Contact = "contact" Contact = "contact"
// webfinger
WebFingerOstatus = "http://ostatus.org/schema/1.0/subscribe"
WebFingerHcard = "http://microformats.org/profile/hcard"
) )
...@@ -33,6 +33,7 @@ type WebfingerXml struct { ...@@ -33,6 +33,7 @@ type WebfingerXml struct {
XMLName xml.Name `xml:"XRD"` XMLName xml.Name `xml:"XRD"`
Xmlns string `xml:"xmlns,attr"` Xmlns string `xml:"xmlns,attr"`
Subject string `xml:"Subject,omitempty"` Subject string `xml:"Subject,omitempty"`
Alias string `xml:"Alias,omitempty"`
Links []WebfingerXmlLink `xml:"Link"` Links []WebfingerXmlLink `xml:"Link"`
} }
...@@ -45,21 +46,24 @@ type WebfingerXmlLink struct { ...@@ -45,21 +46,24 @@ type WebfingerXmlLink struct {
} }
func (w *WebFinger) Discovery() error { func (w *WebFinger) Discovery() error {
err := FetchXml("GET", w.Host + err := FetchXml("GET", w.Host + "/.well-known/host-meta", nil, &w.Xrd)
"/.well-known/host-meta", nil, &w.Xrd)
if err != nil { if err != nil {
return err return err
} }
if len(w.Xrd.Links) < 1 { if len(w.Xrd.Links) < 1 {
return errors.New("XRD Link missing") return errors.New("XRD Link missing")
} }
discoveryUrl := strings.Replace(
w.Xrd.Links[0].Template, for _, link := range w.Xrd.Links {
"{uri}", "acct:" + w.Handle, 1, if link.Rel == "lrdd" && link.Template != "" {
) err = FetchXml("GET", strings.Replace(
err = FetchXml("GET", discoveryUrl, nil, &w.Xrd) link.Template, "{uri}", "acct:" + w.Handle, 1), nil, &w.Xrd)
if err != nil { if err != nil {
return err return err
}
return nil
}
} }
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