- defp valid_topic(%{"hub.topic" => topic}, user) do
- if topic == OStatus.feed_path(user) do
- {:ok, topic}
- else
- {:error, "Wrong topic requested, expected #{OStatus.feed_path(user)}, got #{topic}"}
+ def websub_incoming(conn, %{"id" => id}) do
+ with "sha1=" <> signature <- hd(get_req_header(conn, "x-hub-signature")),
+ signature <- String.downcase(signature),
+ %WebsubClientSubscription{} = websub <- Repo.get(WebsubClientSubscription, id),
+ {:ok, body, _conn} = read_body(conn),
+ ^signature <- Websub.sign(websub.secret, body) do
+ Federator.enqueue(:incoming_doc, body)
+ conn
+ |> send_resp(200, "OK")
+ else _e ->
+ Logger.debug("Can't handle incoming subscription post")
+ conn
+ |> send_resp(500, "Error")