diff --git a/indieAuthServer.go b/indieAuthServer.go index b7dbccc..ad4159f 100644 --- a/indieAuthServer.go +++ b/indieAuthServer.go @@ -35,7 +35,7 @@ var ( // https://indieauth.spec.indieweb.org/#x4-1-1-indieauth-server-metadata func (a *goBlog) indieAuthMetadata(w http.ResponseWriter, r *http.Request) { resp := map[string]any{ - "issuer": a.getFullAddress("/"), + "issuer": a.getInstanceRootURL(), "authorization_endpoint": a.getFullAddress(indieAuthPath), "token_endpoint": a.getFullAddress(indieAuthPath + indieAuthTokenSubpath), "introspection_endpoint": a.getFullAddress(indieAuthPath + indieAuthTokenSubpath), @@ -87,7 +87,8 @@ func (a *goBlog) indieAuthAccept(w http.ResponseWriter, r *http.Request) { query := url.Values{} query.Set("code", code) query.Set("state", iareq.State) - query.Set("iss", a.getFullAddress("/")) + query.Set("iss", a.getInstanceRootURL()) + query.Set("me", a.getInstanceRootURL()) http.Redirect(w, r, iareq.RedirectURI+"?"+query.Encode(), http.StatusFound) } @@ -153,7 +154,7 @@ func (a *goBlog) indieAuthVerification(w http.ResponseWriter, r *http.Request, w } // Generate response resp := map[string]any{ - "me": a.getFullAddress("") + "/", // MUST contain a path component / trailing slash + "me": a.getInstanceRootURL(), } if withToken { // Generate and save token @@ -230,7 +231,7 @@ func (a *goBlog) indieAuthTokenVerification(w http.ResponseWriter, r *http.Reque } else { res = map[string]any{ "active": true, - "me": a.getFullAddress("") + "/", // MUST contain a path component / trailing slash + "me": a.getInstanceRootURL(), "client_id": data.ClientID, "scope": strings.Join(data.Scopes, " "), } diff --git a/paths.go b/paths.go index 7f821a7..211dce6 100644 --- a/paths.go +++ b/paths.go @@ -47,3 +47,7 @@ func (cfg *configServer) getFullAddress(path string) string { } return pa + path } + +func (a *goBlog) getInstanceRootURL() string { + return a.getFullAddress("") + "/" +} diff --git a/paths_test.go b/paths_test.go index 445f98a..b13e367 100644 --- a/paths_test.go +++ b/paths_test.go @@ -44,6 +44,8 @@ func Test_getFullAddress(t *testing.T) { assert.Equal(t, "https://example.net", cfg1.getFullAddress("https://example.net")) assert.Equal(t, "https://example.net", cfg2.getFullAddress("https://example.net")) + + assert.Equal(t, "https://example.com/", app.getInstanceRootURL()) } func Test_getRelativeBlogPath(t *testing.T) {