mirror of https://github.com/jlelse/GoBlog
Rework webfinger to increase compatibility
This commit is contained in:
parent
bbf92a7d09
commit
a114d4d8d9
|
@ -12,7 +12,6 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
@ -22,9 +21,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
apPrivateKey *rsa.PrivateKey
|
apPrivateKey *rsa.PrivateKey
|
||||||
apPostSigner httpsig.Signer
|
apPostSigner httpsig.Signer
|
||||||
apPostSignMutex *sync.Mutex = &sync.Mutex{}
|
apPostSignMutex *sync.Mutex = &sync.Mutex{}
|
||||||
|
webfingerResources map[string]*configBlog
|
||||||
|
webfingerAccts map[string]string
|
||||||
)
|
)
|
||||||
|
|
||||||
func initActivityPub() error {
|
func initActivityPub() error {
|
||||||
|
@ -45,6 +46,15 @@ func initActivityPub() error {
|
||||||
postHooks[postDeleteHook] = append(postHooks[postDeleteHook], func(p *post) {
|
postHooks[postDeleteHook] = append(postHooks[postDeleteHook], func(p *post) {
|
||||||
p.apDelete()
|
p.apDelete()
|
||||||
})
|
})
|
||||||
|
// Prepare webfinger
|
||||||
|
webfingerResources = map[string]*configBlog{}
|
||||||
|
webfingerAccts = map[string]string{}
|
||||||
|
for name, blog := range appConfig.Blogs {
|
||||||
|
acct := "acct:" + name + "@" + appConfig.Server.publicHostname
|
||||||
|
webfingerResources[acct] = blog
|
||||||
|
webfingerResources[blog.apIri()] = blog
|
||||||
|
webfingerAccts[blog.apIri()] = acct
|
||||||
|
}
|
||||||
// Read key and prepare signing
|
// Read key and prepare signing
|
||||||
pkfile, err := os.ReadFile(appConfig.ActivityPub.KeyPath)
|
pkfile, err := os.ReadFile(appConfig.ActivityPub.KeyPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -73,25 +83,28 @@ func initActivityPub() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func apHandleWebfinger(w http.ResponseWriter, r *http.Request) {
|
func apHandleWebfinger(w http.ResponseWriter, r *http.Request) {
|
||||||
re, err := regexp.Compile(`^acct:(.*)@` + regexp.QuoteMeta(appConfig.Server.publicHostname) + `$`)
|
blog, ok := webfingerResources[r.URL.Query().Get("resource")]
|
||||||
if err != nil {
|
if !ok {
|
||||||
serveError(w, r, err.Error(), http.StatusInternalServerError)
|
serveError(w, r, "Resource not found", http.StatusNotFound)
|
||||||
return
|
|
||||||
}
|
|
||||||
name := re.ReplaceAllString(r.URL.Query().Get("resource"), "$1")
|
|
||||||
blog := appConfig.Blogs[name]
|
|
||||||
if blog == nil {
|
|
||||||
serveError(w, r, "Blog not found", http.StatusNotFound)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
b, _ := json.Marshal(map[string]interface{}{
|
b, _ := json.Marshal(map[string]interface{}{
|
||||||
"subject": "acct:" + name + "@" + appConfig.Server.publicHostname,
|
"subject": webfingerAccts[blog.apIri()],
|
||||||
|
"aliases": []string{
|
||||||
|
webfingerAccts[blog.apIri()],
|
||||||
|
blog.apIri(),
|
||||||
|
},
|
||||||
"links": []map[string]string{
|
"links": []map[string]string{
|
||||||
{
|
{
|
||||||
"rel": "self",
|
"rel": "self",
|
||||||
"type": contentTypeAS,
|
"type": contentTypeAS,
|
||||||
"href": blog.apIri(),
|
"href": blog.apIri(),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"rel": "http://webfinger.net/rel/profile-page",
|
||||||
|
"type": "text/html",
|
||||||
|
"href": blog.apIri(),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
w.Header().Set(contentType, "application/jrd+json"+charsetUtf8Suffix)
|
w.Header().Set(contentType, "application/jrd+json"+charsetUtf8Suffix)
|
||||||
|
|
Loading…
Reference in New Issue