forked from AkkomaGang/akkoma
Rename id helper method.
This commit is contained in:
parent
1db0dc3072
commit
dd9bb37893
4 changed files with 9 additions and 19 deletions
|
@ -13,7 +13,7 @@ def call(%{assigns: %{valid_signature: true}} = conn, _opts) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(conn, _opts) do
|
def call(conn, _opts) do
|
||||||
user = Utils.normalize_actor(conn.params["actor"])
|
user = Utils.get_ap_id(conn.params["actor"])
|
||||||
Logger.debug("Checking sig for #{user}")
|
Logger.debug("Checking sig for #{user}")
|
||||||
[signature | _] = get_req_header(conn, "signature")
|
[signature | _] = get_req_header(conn, "signature")
|
||||||
|
|
||||||
|
|
|
@ -263,11 +263,7 @@ def handle_incoming(
|
||||||
def handle_incoming(
|
def handle_incoming(
|
||||||
%{"type" => "Delete", "object" => object_id, "actor" => actor, "id" => _id} = _data
|
%{"type" => "Delete", "object" => object_id, "actor" => actor, "id" => _id} = _data
|
||||||
) do
|
) do
|
||||||
object_id =
|
object_id = Utils.get_ap_id(object_id)
|
||||||
case object_id do
|
|
||||||
%{"id" => id} -> id
|
|
||||||
id -> id
|
|
||||||
end
|
|
||||||
|
|
||||||
with %User{} = _actor <- User.get_or_fetch_by_ap_id(actor),
|
with %User{} = _actor <- User.get_or_fetch_by_ap_id(actor),
|
||||||
{:ok, object} <-
|
{:ok, object} <-
|
||||||
|
@ -365,9 +361,6 @@ def handle_incoming(
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO
|
|
||||||
# Accept
|
|
||||||
|
|
||||||
def handle_incoming(_), do: :error
|
def handle_incoming(_), do: :error
|
||||||
|
|
||||||
def get_obj_helper(id) do
|
def get_obj_helper(id) do
|
||||||
|
|
|
@ -7,18 +7,15 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
||||||
|
|
||||||
# Some implementations send the actor URI as the actor field, others send the entire actor object,
|
# Some implementations send the actor URI as the actor field, others send the entire actor object,
|
||||||
# so figure out what the actor's URI is based on what we have.
|
# so figure out what the actor's URI is based on what we have.
|
||||||
def normalize_actor(actor) do
|
def get_ap_id(object) do
|
||||||
cond do
|
case object do
|
||||||
is_binary(actor) ->
|
%{"id" => id} -> id
|
||||||
actor
|
id -> id
|
||||||
|
|
||||||
is_map(actor) ->
|
|
||||||
actor["id"]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalize_params(params) do
|
def normalize_params(params) do
|
||||||
Map.put(params, "actor", normalize_actor(params["actor"]))
|
Map.put(params, "actor", get_ap_id(params["actor"]))
|
||||||
end
|
end
|
||||||
|
|
||||||
def make_json_ld_header do
|
def make_json_ld_header do
|
||||||
|
|
|
@ -32,14 +32,14 @@ def validate(headers, signature, public_key) do
|
||||||
def validate_conn(conn) do
|
def validate_conn(conn) do
|
||||||
# TODO: How to get the right key and see if it is actually valid for that request.
|
# TODO: How to get the right key and see if it is actually valid for that request.
|
||||||
# For now, fetch the key for the actor.
|
# For now, fetch the key for the actor.
|
||||||
with actor_id <- Utils.normalize_actor(conn.params["actor"]),
|
with actor_id <- Utils.get_ap_id(conn.params["actor"]),
|
||||||
{:ok, public_key} <- User.get_public_key_for_ap_id(actor_id) do
|
{:ok, public_key} <- User.get_public_key_for_ap_id(actor_id) do
|
||||||
if validate_conn(conn, public_key) do
|
if validate_conn(conn, public_key) do
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
Logger.debug("Could not validate, re-fetching user and trying one more time")
|
Logger.debug("Could not validate, re-fetching user and trying one more time")
|
||||||
# Fetch user anew and try one more time
|
# Fetch user anew and try one more time
|
||||||
with actor_id <- Utils.normalize_actor(conn.params["actor"]),
|
with actor_id <- Utils.get_ap_id(conn.params["actor"]),
|
||||||
{:ok, _user} <- ActivityPub.make_user_from_ap_id(actor_id),
|
{:ok, _user} <- ActivityPub.make_user_from_ap_id(actor_id),
|
||||||
{:ok, public_key} <- User.get_public_key_for_ap_id(actor_id) do
|
{:ok, public_key} <- User.get_public_key_for_ap_id(actor_id) do
|
||||||
validate_conn(conn, public_key)
|
validate_conn(conn, public_key)
|
||||||
|
|
Loading…
Reference in a new issue