Fix login with micro.blog iOS app

This commit is contained in:
Jan-Lukas Else 2022-10-15 14:19:12 +02:00
parent 5256b3929b
commit f9d568acc8
3 changed files with 11 additions and 4 deletions

View File

@ -35,7 +35,7 @@ var (
// https://indieauth.spec.indieweb.org/#x4-1-1-indieauth-server-metadata // https://indieauth.spec.indieweb.org/#x4-1-1-indieauth-server-metadata
func (a *goBlog) indieAuthMetadata(w http.ResponseWriter, r *http.Request) { func (a *goBlog) indieAuthMetadata(w http.ResponseWriter, r *http.Request) {
resp := map[string]any{ resp := map[string]any{
"issuer": a.getFullAddress("/"), "issuer": a.getInstanceRootURL(),
"authorization_endpoint": a.getFullAddress(indieAuthPath), "authorization_endpoint": a.getFullAddress(indieAuthPath),
"token_endpoint": a.getFullAddress(indieAuthPath + indieAuthTokenSubpath), "token_endpoint": a.getFullAddress(indieAuthPath + indieAuthTokenSubpath),
"introspection_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 := url.Values{}
query.Set("code", code) query.Set("code", code)
query.Set("state", iareq.State) 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) 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 // Generate response
resp := map[string]any{ resp := map[string]any{
"me": a.getFullAddress("") + "/", // MUST contain a path component / trailing slash "me": a.getInstanceRootURL(),
} }
if withToken { if withToken {
// Generate and save token // Generate and save token
@ -230,7 +231,7 @@ func (a *goBlog) indieAuthTokenVerification(w http.ResponseWriter, r *http.Reque
} else { } else {
res = map[string]any{ res = map[string]any{
"active": true, "active": true,
"me": a.getFullAddress("") + "/", // MUST contain a path component / trailing slash "me": a.getInstanceRootURL(),
"client_id": data.ClientID, "client_id": data.ClientID,
"scope": strings.Join(data.Scopes, " "), "scope": strings.Join(data.Scopes, " "),
} }

View File

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

View File

@ -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", cfg1.getFullAddress("https://example.net"))
assert.Equal(t, "https://example.net", cfg2.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) { func Test_getRelativeBlogPath(t *testing.T) {