diff options
author | Julio Capote <jcapote@gmail.com> | 2023-01-02 14:32:41 +0000 |
---|---|---|
committer | Julio Capote <jcapote@gmail.com> | 2023-01-02 14:32:41 +0000 |
commit | 9027aba0621018caf177611d9105213645efe491 (patch) | |
tree | dde99a394273708c231332ae9fc9fb1ff273826a /registry/registry.go | |
parent | 91a081a2bc16540c37ac76a719ab4dd79608ed5d (diff) | |
download | communique-9027aba0621018caf177611d9105213645efe491.tar.gz |
fix webfinger
Diffstat (limited to 'registry/registry.go')
-rw-r--r-- | registry/registry.go | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/registry/registry.go b/registry/registry.go index a24d2d7..451704e 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -3,7 +3,8 @@ package registry import ( "bytes" "encoding/gob" - "fmt" + "net/url" + "strings" "git.capotej.com/capotej/communique/config" "git.capotej.com/capotej/communique/models" @@ -26,7 +27,7 @@ func NewRegistry(cfg config.Config, persister *models.Persister) *Registry { reg := Registry{cfg: cfg, persister: persister} reg.handlerMap = make(map[string]Handler) for _, v := range cfg.Handlers { - reg.handlerMap[fqn(v.Name, cfg.Domain)] = Handler{handlerCfg: v} + reg.handlerMap[v.Name] = Handler{handlerCfg: v} } return ® } @@ -148,29 +149,35 @@ func (r *Registry) ActivityOrNote(activityOrNote, name, id string) (map[string]i return views.RenderNote(handler.handlerCfg.Name, r.cfg.Domain, outboxItem) } -func (r *Registry) WebfingerResource(fqn string) (*views.WebfingerResource, error) { - handler := r.findByFQN(fqn) - if handler == nil { - handler = r.findByFQN("acct:" + fqn) +// This has to handle various lookup formats: +// ?resource=acct:actor@domain +// ?resource=actor@domain +// ?resource=actor +// ?resource=acct:actor +func (r *Registry) Webfinger(fqn string) (*views.WebfingerResource, error) { + // Strip away acct: prefix, if found + fqn = strings.TrimPrefix(fqn, "acct:") + + // Strip away @domain suffix, if found + domainUrl, err := url.Parse(r.cfg.Domain) + if err != nil { + return nil, err } + hostname := "@" + domainUrl.Hostname() + fqn = strings.TrimSuffix(fqn, hostname) + + // We should just have $actor left + handler := r.findByName(fqn) if handler == nil { return nil, nil } - return views.RenderWebfingerResource(handler.handlerCfg.Name, r.cfg.Domain) + return views.RenderWebfinger(handler.handlerCfg.Name, r.cfg.Domain, hostname) } -func fqn(name, domain string) string { - return fmt.Sprintf("acct:%s@%s", name, domain) -} - -func (r *Registry) findByFQN(fqn string) *Handler { - handler, ok := r.handlerMap[fqn] +func (r *Registry) findByName(name string) *Handler { + handler, ok := r.handlerMap[name] if !ok { return nil } return &handler } - -func (r *Registry) findByName(name string) *Handler { - return r.findByFQN(fqn(name, r.cfg.Domain)) -} |