[feature] Provide .well-known/host-meta endpoint (#1604)

* [feature] Provide .well-known/host-meta endpoint

This adds the host-meta endpoint as Mastodon clients use this to
discover the API domain to use when the host and account domains aren't
the same.

* Address review comments
This commit is contained in:
Daenney
2023-03-09 18:55:45 +01:00
committed by GitHub
parent 9ba35c65eb
commit a312238e79
9 changed files with 167 additions and 4 deletions

View File

@ -28,6 +28,10 @@ import (
)
const (
hostMetaXMLNS = "http://docs.oasis-open.org/ns/xri/xrd-1.0"
hostMetaRel = "lrdd"
hostMetaType = "application/xrd+xml"
hostMetaTemplate = ".well-known/webfinger?resource={uri}"
nodeInfoVersion = "2.0"
nodeInfoSoftwareName = "gotosocial"
nodeInfoRel = "http://nodeinfo.diaspora.software/ns/schema/" + nodeInfoVersion
@ -96,6 +100,22 @@ func (p *Processor) NodeInfoGet(ctx context.Context) (*apimodel.Nodeinfo, gtserr
}, nil
}
// HostMetaGet returns a host-meta struct in response to a host-meta request.
func (p *Processor) HostMetaGet() *apimodel.HostMeta {
protocol := config.GetProtocol()
host := config.GetHost()
return &apimodel.HostMeta{
XMLNS: hostMetaXMLNS,
Link: []apimodel.Link{
{
Rel: hostMetaRel,
Type: hostMetaType,
Template: fmt.Sprintf("%s://%s/%s", protocol, host, hostMetaTemplate),
},
},
}
}
// WebfingerGet handles the GET for a webfinger resource. Most commonly, it will be used for returning account lookups.
func (p *Processor) WebfingerGet(ctx context.Context, requestedUsername string) (*apimodel.WellKnownResponse, gtserror.WithCode) {
// Get the local account the request is referring to.