Unverified Commit 779f47bf authored by zauberstuhl's avatar zauberstuhl Committed by GitHub
Browse files

Merge pull request #6 from ganggo/webfinger_support

Support old xml webfinger request
parents 12749ba5 d172801c
...@@ -26,49 +26,43 @@ import ( ...@@ -26,49 +26,43 @@ import (
type WebFinger struct { type WebFinger struct {
Host string Host string
Handle string Handle string
Json WebfingerJson Data WebfingerData
} }
// TODO XML webfinger is deprecated but type WebfingerData struct {
// still used in host-meta which is required // xml
// for a successful pod-active check XMLName xml.Name `xml:"XRD" json:"-"`
type WebfingerXml struct { Xmlns string `xml:"xmlns,attr" json:"-"`
XMLName xml.Name `xml:"XRD"` Alias string `xml:"Alias,omitempty" json:"-"`
Xmlns string `xml:"xmlns,attr"` // json
Subject string `xml:"Subject,omitempty"` Aliases []string `json:"aliases" xml:"-"`
Alias string `xml:"Alias,omitempty"`
Links []WebfingerXmlLink `xml:"Link"`
}
type WebfingerXmlLink struct { Subject string `json:"subject" xml:"Subject,omitempty"`
XMLName xml.Name `xml:"Link"` Links []WebfingerDataLink `json:"links" xml:"Link"`
Rel string `xml:"rel,attr"`
Type string `xml:"type,attr"`
Template string `xml:"template,attr,omitempty"`
Href string `xml:"href,attr,omitempty"`
} }
type WebfingerJson struct { type WebfingerDataLink struct {
Subject string `json:"subject"` // xml
Aliases []string `json:"aliases"` XMLName xml.Name `xml:"Link" json:"-"`
Links []WebfingerJsonLink `json:"links"`
}
type WebfingerJsonLink struct { Rel string `json:"rel" xml:"rel,attr"`
Rel string `json:"rel"` Type string `json:"type,omitempty" xml:"type,attr"`
Type string `json:"type,omitempty"` Href string `json:"href,omitempty" xml:"href,attr,omitempty"`
Href string `json:"href,omitempty"` Template string `json:"template,omitempty" xml:"template,attr,omitempty"`
Template string `json:"template,omitempty"`
} }
func (w *WebFinger) Discovery() error { func (w *WebFinger) Discovery() error {
url := fmt.Sprintf("%s/.well-known/webfinger?resource=acct:%s", w.Host, w.Handle) url := fmt.Sprintf("%s/.well-known/webfinger?resource=acct:%s", w.Host, w.Handle)
err := FetchJson("GET", url, nil, &w.Json) err := FetchJson("GET", url, nil, &w.Data)
if err != nil { if err != nil {
return err url = fmt.Sprintf("%s/webfinger?q=acct:%s", w.Host, w.Handle)
err = FetchXml("GET", url, nil, &w.Data)
if err != nil {
return err
}
} }
if len(w.Json.Links) < 1 { if len(w.Data.Links) < 1 {
return errors.New("Webfinger Links missing") return errors.New("Webfinger Links missing")
} }
return nil return nil
......
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