Fix login with micro.blog iOS app

master
Jan-Lukas Else 2 months ago
parent 5256b3929b
commit f9d568acc8
  1. 9
      indieAuthServer.go
  2. 4
      paths.go
  3. 2
      paths_test.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, " "),
}

@ -47,3 +47,7 @@ func (cfg *configServer) getFullAddress(path string) string {
}
return pa + path
}
func (a *goBlog) getInstanceRootURL() string {
return a.getFullAddress("") + "/"
}

@ -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) {

Loading…
Cancel
Save