Changes
5 changed files (+80/-39)
-
-
@@ -8,7 +8,6 @@ import ("context" "strings" "code.gitea.io/gitea/models/auth" user_model "code.gitea.io/gitea/models/user" ap "github.com/go-ap/activitypub"
-
@@ -22,24 +21,15 @@ objectIRISplit := strings.Split(objectIRI.String(), "/")actorName := actorIRISplit[len(actorIRISplit)-1] objectName := objectIRISplit[len(actorIRISplit)-1] actorUser, err := user_model.GetUserByName(ctx, actorName) if err != nil { // Create user // TODO: Move this to a function actorUser := &user_model.User{ Name: actorName, LoginType: auth.Federated, LoginName: actorIRI.String(), } user_model.CreateUser(actorUser) actorUser, _ = user_model.GetUserByName(ctx, actorName) } FederatedUserNew(actorName, actorIRI) actorUser, _ := user_model.GetUserByName(ctx, actorName) objectUser, _ := user_model.GetUserByName(ctx, objectName) user_model.FollowUser(actorUser.ID, objectUser.ID) accept := ap.AcceptNew(objectIRI, activity) accept.Actor = activity.Object accept.To = ap.ItemCollection{actorIRI} // TODO: send the Accept activity to the object's inbox } Send(objectUser, accept) }
-
-
-
@@ -0,0 +1,50 @@// Copyright 2022 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. package activitypub import ( "fmt" "io" "net/http" "net/url" "time" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/httplib" "code.gitea.io/gitea/modules/setting" ap "github.com/go-ap/activitypub" ) func Fetch(iri *url.URL) (b []byte, err error) { req := httplib.NewRequest(iri.String(), http.MethodGet) req.Header("Accept", ActivityStreamsContentType) req.Header("Accept-Charset", "utf-8") req.Header("Date", fmt.Sprintf("%s UTC", time.Now().UTC().Format(time.RFC1123))) resp, err := req.Response() if err != nil { return } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { err = fmt.Errorf("url IRI fetch [%s] failed with status (%d): %s", iri, resp.StatusCode, resp.Status) return } b, err = io.ReadAll(resp.Body) return } func Send(user *user_model.User, activity *ap.Activity) { body, err := activity.MarshalJSON() if err != nil { return } for _, to := range activity.To { client, _ := NewClient(user, setting.AppURL+"api/v1/activitypub/user/"+user.Name+"#main-key") client.Post(body, to.GetID().String()) } }
-
-
-
@@ -0,0 +1,24 @@// Copyright 2022 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. package activitypub import ( "strings" "code.gitea.io/gitea/models/auth" user_model "code.gitea.io/gitea/models/user" ap "github.com/go-ap/activitypub" ) func FederatedUserNew(name string, IRI ap.IRI) error { instance := strings.Split(IRI.String(), "/")[2] user := &user_model.User{ Name: name + "@" + instance, LoginType: auth.Federated, Website: IRI.String(), } return user_model.CreateUser(user) }
-
-
-
@@ -10,14 +10,11 @@ "crypto""crypto/x509" "encoding/pem" "fmt" "io" "net/http" "net/url" "time" "code.gitea.io/gitea/modules/activitypub" gitea_context "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/httplib" "code.gitea.io/gitea/modules/setting" ap "github.com/go-ap/activitypub"
-
@@ -46,25 +43,6 @@ p, err = x509.ParsePKIXPublicKey(block.Bytes)return } func fetch(iri *url.URL) (b []byte, err error) { req := httplib.NewRequest(iri.String(), http.MethodGet) req.Header("Accept", activitypub.ActivityStreamsContentType) req.Header("Accept-Charset", "utf-8") req.Header("Date", fmt.Sprintf("%s UTC", time.Now().UTC().Format(time.RFC1123))) resp, err := req.Response() if err != nil { return } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { err = fmt.Errorf("url IRI fetch [%s] failed with status (%d): %s", iri, resp.StatusCode, resp.Status) return } b, err = io.ReadAll(resp.Body) return } func verifyHTTPSignatures(ctx *gitea_context.APIContext) (authenticated bool, err error) { r := ctx.Req
-
@@ -79,7 +57,7 @@ if err != nil {return } // 2. Fetch the public key of the other actor b, err := fetch(idIRI) b, err := activitypub.Fetch(idIRI) if err != nil { return }
-
-
-
@@ -593,7 +593,6 @@ // for users that have already signed in.func buildAuthGroup() *auth.Group { group := auth.NewGroup( &auth.OAuth2{}, &auth.HTTPSign{}, &auth.Basic{}, // FIXME: this should be removed once we don't allow basic auth in API ) if setting.Service.EnableReverseProxyAuth {
-