-
Notifications
You must be signed in to change notification settings - Fork 11
/
webfinger.go
57 lines (49 loc) · 1.35 KB
/
webfinger.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package readas
import (
"github.com/writeas/go-webfinger"
"github.com/writeas/impart"
"net/http"
"strings"
)
type wfResolver struct {
app *app
}
var wfUserNotFoundErr = impart.HTTPError{http.StatusNotFound, "User not found."}
func (wfr wfResolver) FindUser(username string, host, requestHost string, r []webfinger.Rel) (*webfinger.Resource, error) {
realHost := wfr.app.cfg.Host[strings.LastIndexByte(wfr.app.cfg.Host, '/')+1:]
if host != realHost {
return nil, impart.HTTPError{http.StatusBadRequest, "Host doesn't match"}
}
u, err := wfr.app.getLocalUser(username)
if err != nil {
return nil, err
}
profileURL := wfr.app.cfg.Host + "/" + username
res := webfinger.Resource{
Subject: "acct:" + username + "@" + host,
Aliases: []string{
profileURL,
u.AccountRoot(wfr.app),
},
Links: []webfinger.Link{
{
HRef: profileURL,
Type: "text/html",
Rel: "https://webfinger.net/rel/profile-page",
},
{
HRef: u.AccountRoot(wfr.app),
Type: "application/activity+json",
Rel: "self",
},
},
}
return &res, nil
}
func (wfr wfResolver) DummyUser(username string, hostname string, r []webfinger.Rel) (*webfinger.Resource, error) {
return nil, impart.HTTPError{http.StatusNotFound, "User not found."}
}
func (wfr wfResolver) IsNotFoundError(err error) bool {
// TODO: actually check error value
return err != nil
}