diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-04-04 10:08:23 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-04 10:08:23 +0800 |
commit | 17f23182ffdada3dee6a01ab2b49547e680bb02c (patch) | |
tree | fd0a62a042183da3dca5911440db68ab2f12b1bb /routers | |
parent | 5115ffa90c959086704b6e3437214a192de7b8a7 (diff) | |
download | gitea-17f23182ffdada3dee6a01ab2b49547e680bb02c.tar.gz gitea-17f23182ffdada3dee6a01ab2b49547e680bb02c.zip |
Use User.ID instead of User.Name in ActivityPub API for Person IRI (#23823)
Thanks to @trwnh
Close #23802
The ActivityPub id is an HTTPS URI that should remain constant, even if
the user changes their name.
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/activitypub/person.go | 20 | ||||
-rw-r--r-- | routers/api/v1/api.go | 5 | ||||
-rw-r--r-- | routers/web/webfinger.go | 4 |
3 files changed, 18 insertions, 11 deletions
diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index 492930b849..bc6b82b179 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -4,6 +4,7 @@ package activitypub import ( + "fmt" "net/http" "strings" @@ -18,22 +19,23 @@ import ( // Person function returns the Person actor for a user func Person(ctx *context.APIContext) { - // swagger:operation GET /activitypub/user/{username} activitypub activitypubPerson + // swagger:operation GET /activitypub/user-id/{user-id} activitypub activitypubPerson // --- // summary: Returns the Person actor for a user // produces: // - application/json // parameters: - // - name: username + // - name: user-id // in: path - // description: username of the user - // type: string + // description: user ID of the user + // type: integer // required: true // responses: // "200": // "$ref": "#/responses/ActivityPub" - link := strings.TrimSuffix(setting.AppURL, "/") + "/api/v1/activitypub/user/" + ctx.ContextUser.Name + // TODO: the setting.AppURL during the test doesn't follow the definition: "It always has a '/' suffix" + link := fmt.Sprintf("%s/api/v1/activitypub/user-id/%d", strings.TrimSuffix(setting.AppURL, "/"), ctx.ContextUser.ID) person := ap.PersonNew(ap.IRI(link)) person.Name = ap.NaturalLanguageValuesNew() @@ -85,16 +87,16 @@ func Person(ctx *context.APIContext) { // PersonInbox function handles the incoming data for a user inbox func PersonInbox(ctx *context.APIContext) { - // swagger:operation POST /activitypub/user/{username}/inbox activitypub activitypubPersonInbox + // swagger:operation POST /activitypub/user-id/{user-id}/inbox activitypub activitypubPersonInbox // --- // summary: Send to the inbox // produces: // - application/json // parameters: - // - name: username + // - name: user-id // in: path - // description: username of the user - // type: string + // description: user ID of the user + // type: integer // required: true // responses: // "204": diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 8b13f5492c..21797bd1a0 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -704,10 +704,15 @@ func Routes(ctx gocontext.Context) *web.Route { if setting.Federation.Enabled { m.Get("/nodeinfo", misc.NodeInfo) m.Group("/activitypub", func() { + // deprecated, remove in 1.20, use /user-id/{user-id} instead m.Group("/user/{username}", func() { m.Get("", activitypub.Person) m.Post("/inbox", activitypub.ReqHTTPSignature(), activitypub.PersonInbox) }, context_service.UserAssignmentAPI()) + m.Group("/user-id/{user-id}", func() { + m.Get("", activitypub.Person) + m.Post("/inbox", activitypub.ReqHTTPSignature(), activitypub.PersonInbox) + }, context_service.UserIDAssignmentAPI()) }) } m.Get("/signing-key.gpg", misc.SigningKey) diff --git a/routers/web/webfinger.go b/routers/web/webfinger.go index a8e816d7b7..1442e09a31 100644 --- a/routers/web/webfinger.go +++ b/routers/web/webfinger.go @@ -85,7 +85,7 @@ func WebfingerQuery(ctx *context.Context) { aliases := []string{ u.HTMLURL(), - appURL.String() + "api/v1/activitypub/user/" + url.PathEscape(u.Name), + appURL.String() + "api/v1/activitypub/user-id/" + fmt.Sprint(u.ID), } if !u.KeepEmailPrivate { aliases = append(aliases, fmt.Sprintf("mailto:%s", u.Email)) @@ -104,7 +104,7 @@ func WebfingerQuery(ctx *context.Context) { { Rel: "self", Type: "application/activity+json", - Href: appURL.String() + "api/v1/activitypub/user/" + url.PathEscape(u.Name), + Href: appURL.String() + "api/v1/activitypub/user-id/" + fmt.Sprint(u.ID), }, } |