Cache remote user public keys
This commit is contained in:
parent
ecefb6a2d0
commit
0b97c6aa69
|
@ -39,7 +39,7 @@ func AuthorizeInteraction(ctx *context.Context) {
|
||||||
ctx.ServerError("UnmarshalJSON", err)
|
ctx.ServerError("UnmarshalJSON", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = FederatedUserNew(ctx, object.(ap.Person))
|
err = FederatedUserNew(ctx, object.(*ap.Person))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("FederatedUserNew", err)
|
ctx.ServerError("FederatedUserNew", err)
|
||||||
return
|
return
|
||||||
|
@ -52,6 +52,10 @@ func AuthorizeInteraction(ctx *context.Context) {
|
||||||
ctx.Redirect(name)
|
ctx.Redirect(name)
|
||||||
case forgefed.RepositoryType:
|
case forgefed.RepositoryType:
|
||||||
err = FederatedRepoNew(ctx, object.(forgefed.Repository))
|
err = FederatedRepoNew(ctx, object.(forgefed.Repository))
|
||||||
|
if err != nil {
|
||||||
|
ctx.ServerError("FederatedRepoNew", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Status(http.StatusOK)
|
ctx.Status(http.StatusOK)
|
||||||
|
|
|
@ -6,6 +6,7 @@ package activitypub
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/auth"
|
"code.gitea.io/gitea/models/auth"
|
||||||
|
@ -16,7 +17,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Create a new federated user from a Person object
|
// Create a new federated user from a Person object
|
||||||
func FederatedUserNew(ctx context.Context, person ap.Person) error {
|
func FederatedUserNew(ctx context.Context, person *ap.Person) error {
|
||||||
name, err := personIRIToName(person.GetLink())
|
name, err := personIRIToName(person.GetLink())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -47,6 +48,10 @@ func FederatedUserNew(ctx context.Context, person ap.Person) error {
|
||||||
avatar = ""
|
avatar = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if person.PublicKey.PublicKeyPem == "" {
|
||||||
|
return errors.New("person public key not found")
|
||||||
|
}
|
||||||
|
|
||||||
user := &user_model.User{
|
user := &user_model.User{
|
||||||
Name: name,
|
Name: name,
|
||||||
FullName: person.Name.String(), // May not exist!!
|
FullName: person.Name.String(), // May not exist!!
|
||||||
|
@ -55,5 +60,14 @@ func FederatedUserNew(ctx context.Context, person ap.Person) error {
|
||||||
LoginType: auth.Federated,
|
LoginType: auth.Federated,
|
||||||
LoginName: person.GetLink().String(),
|
LoginName: person.GetLink().String(),
|
||||||
}
|
}
|
||||||
return user_model.CreateUser(user)
|
err = user_model.CreateUser(user)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = user_model.SetUserSetting(user.ID, user_model.UserActivityPubPrivPem, "")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return user_model.SetUserSetting(user.ID, user_model.UserActivityPubPubPem, person.PublicKey.PublicKeyPem)
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ func verifyHTTPSignatures(ctx *gitea_context.APIContext) (authenticated bool, er
|
||||||
// 4. Create a federated user for the actor
|
// 4. Create a federated user for the actor
|
||||||
var person ap.Person
|
var person ap.Person
|
||||||
person.UnmarshalJSON(b)
|
person.UnmarshalJSON(b)
|
||||||
err = activitypub.FederatedUserNew(ctx, person)
|
err = activitypub.FederatedUserNew(ctx, &person)
|
||||||
return authenticated, err
|
return authenticated, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in New Issue