Support /authorize-interaction route used by Mastodon
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
e3ea311cd5
commit
c62696c8e7
|
@ -0,0 +1 @@
|
||||||
|
Support /authorize-interaction route used by Mastodon
|
|
@ -465,6 +465,8 @@ defmodule Pleroma.Web.Router do
|
||||||
get("/main/ostatus", UtilController, :show_subscribe_form)
|
get("/main/ostatus", UtilController, :show_subscribe_form)
|
||||||
get("/ostatus_subscribe", RemoteFollowController, :follow)
|
get("/ostatus_subscribe", RemoteFollowController, :follow)
|
||||||
post("/ostatus_subscribe", RemoteFollowController, :do_follow)
|
post("/ostatus_subscribe", RemoteFollowController, :do_follow)
|
||||||
|
|
||||||
|
get("/authorize_interaction", RemoteFollowController, :authorize_interaction)
|
||||||
end
|
end
|
||||||
|
|
||||||
scope "/api/pleroma", Pleroma.Web.TwitterAPI do
|
scope "/api/pleroma", Pleroma.Web.TwitterAPI do
|
||||||
|
|
|
@ -121,6 +121,13 @@ def do_follow(%{assigns: %{user: nil}} = conn, _) do
|
||||||
render(conn, "followed.html", %{error: "Insufficient permissions: follow | write:follows."})
|
render(conn, "followed.html", %{error: "Insufficient permissions: follow | write:follows."})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# GET /authorize_interaction
|
||||||
|
#
|
||||||
|
def authorize_interaction(conn, %{"uri" => uri}) do
|
||||||
|
conn
|
||||||
|
|> redirect(to: Routes.remote_follow_path(conn, :follow, %{acct: uri}))
|
||||||
|
end
|
||||||
|
|
||||||
defp handle_follow_error(conn, {:mfa_token, followee, _} = _) do
|
defp handle_follow_error(conn, {:mfa_token, followee, _} = _) do
|
||||||
render(conn, "follow_login.html", %{error: "Wrong username or password", followee: followee})
|
render(conn, "follow_login.html", %{error: "Wrong username or password", followee: followee})
|
||||||
end
|
end
|
||||||
|
|
|
@ -82,6 +82,7 @@ test "api routes are detected correctly" do
|
||||||
"api",
|
"api",
|
||||||
"main",
|
"main",
|
||||||
"ostatus_subscribe",
|
"ostatus_subscribe",
|
||||||
|
"authorize_interaction",
|
||||||
"oauth",
|
"oauth",
|
||||||
"objects",
|
"objects",
|
||||||
"activities",
|
"activities",
|
||||||
|
|
|
@ -455,4 +455,38 @@ test "local avatar is not proxied" do
|
||||||
assert avatar_url == "#{Pleroma.Web.Endpoint.url()}/localuser/avatar.png"
|
assert avatar_url == "#{Pleroma.Web.Endpoint.url()}/localuser/avatar.png"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "GET /authorize_interaction - authorize_interaction/2" do
|
||||||
|
test "redirects to /ostatus_subscribe", %{conn: conn} do
|
||||||
|
Tesla.Mock.mock(fn
|
||||||
|
%{method: :get, url: "https://mastodon.social/users/emelie"} ->
|
||||||
|
%Tesla.Env{
|
||||||
|
status: 200,
|
||||||
|
headers: [{"content-type", "application/activity+json"}],
|
||||||
|
body: File.read!("test/fixtures/tesla_mock/emelie.json")
|
||||||
|
}
|
||||||
|
|
||||||
|
%{method: :get, url: "https://mastodon.social/users/emelie/collections/featured"} ->
|
||||||
|
%Tesla.Env{
|
||||||
|
status: 200,
|
||||||
|
headers: [{"content-type", "application/activity+json"}],
|
||||||
|
body:
|
||||||
|
File.read!("test/fixtures/users_mock/masto_featured.json")
|
||||||
|
|> String.replace("{{domain}}", "mastodon.social")
|
||||||
|
|> String.replace("{{nickname}}", "emelie")
|
||||||
|
}
|
||||||
|
end)
|
||||||
|
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> get(
|
||||||
|
remote_follow_path(conn, :authorize_interaction, %{
|
||||||
|
uri: "https://mastodon.social/users/emelie"
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
assert redirected_to(conn) ==
|
||||||
|
remote_follow_path(conn, :follow, %{acct: "https://mastodon.social/users/emelie"})
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue