This repository has been archived on 2024-01-11. You can view files and clone it, but cannot push or open issues or pull requests.
gitea/modules/activitypub/authorize_interaction.go

59 lines
1.2 KiB
Go
Raw Normal View History

// 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 (
"net/http"
"net/url"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/forgefed"
ap "github.com/go-ap/activitypub"
)
2022-07-27 19:43:01 +00:00
func AuthorizeInteraction(ctx *context.Context) {
uri, err := url.Parse(ctx.Req.URL.Query().Get("uri"))
if err != nil {
2022-07-27 19:43:01 +00:00
ctx.ServerError("Could not parse URI", err)
return
}
resp, err := Fetch(uri)
if err != nil {
2022-07-27 19:43:01 +00:00
ctx.ServerError("Fetch", err)
return
}
ap.ItemTyperFunc = forgefed.GetItemByType
object, err := ap.UnmarshalJSON(resp)
if err != nil {
2022-07-27 19:43:01 +00:00
ctx.ServerError("UnmarshalJSON", err)
return
}
switch object.GetType() {
case ap.PersonType:
if err != nil {
2022-07-27 19:43:01 +00:00
ctx.ServerError("UnmarshalJSON", err)
return
}
2022-07-27 19:43:01 +00:00
err = FederatedUserNew(ctx, object.(ap.Person))
if err != nil {
2022-07-27 19:43:01 +00:00
ctx.ServerError("FederatedUserNew", err)
return
}
name, err := personIRIToName(object.GetLink())
if err != nil {
2022-07-27 19:43:01 +00:00
ctx.ServerError("personIRIToName", err)
return
}
2022-07-27 19:43:01 +00:00
ctx.Redirect(name)
case forgefed.RepositoryType:
2022-07-27 19:43:01 +00:00
err = FederatedRepoNew(ctx, object.(forgefed.Repository))
}
2022-07-27 19:43:01 +00:00
ctx.Status(http.StatusOK)
}