summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorlain <lain@soykaf.club>2019-11-11 12:27:33 +0000
committerlain <lain@soykaf.club>2019-11-11 12:27:33 +0000
commit1ca7b877a153d57f34f3d5a4b380a824d5d4b809 (patch)
tree823110629b7f464229e16a58e455e4583e2c9d1e /lib
parent417f9a782f3a8b549c6b2493b0965e68eddc9403 (diff)
parente1fc6cb78f07653300965d212d9c5ece9f5c3de0 (diff)
downloadpleroma-1ca7b877a153d57f34f3d5a4b380a824d5d4b809.tar.gz
pleroma-1ca7b877a153d57f34f3d5a4b380a824d5d4b809.zip
Merge branch 'iss-1376' into 'develop'
Check client and token in GET /oauth/authorize See merge request pleroma/pleroma!1940
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/oauth/oauth_controller.ex18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex
index 1b1394787..2aee8cab2 100644
--- a/lib/pleroma/web/oauth/oauth_controller.ex
+++ b/lib/pleroma/web/oauth/oauth_controller.ex
@@ -37,7 +37,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do
authorize(conn, Map.merge(params, auth_attrs))
end
- def authorize(%Plug.Conn{assigns: %{token: %Token{}}} = conn, params) do
+ def authorize(%Plug.Conn{assigns: %{token: %Token{}}} = conn, %{"force_login" => _} = params) do
if ControllerHelper.truthy_param?(params["force_login"]) do
do_authorize(conn, params)
else
@@ -45,6 +45,22 @@ defmodule Pleroma.Web.OAuth.OAuthController do
end
end
+ # Note: the token is set in oauth_plug, but the token and client do not always go together.
+ # For example, MastodonFE's token is set if user requests with another client,
+ # after user already authorized to MastodonFE.
+ # So we have to check client and token.
+ def authorize(
+ %Plug.Conn{assigns: %{token: %Token{} = token}} = conn,
+ %{"client_id" => client_id} = params
+ ) do
+ with %Token{} = t <- Repo.get_by(Token, token: token.token) |> Repo.preload(:app),
+ ^client_id <- t.app.client_id do
+ handle_existing_authorization(conn, params)
+ else
+ _ -> do_authorize(conn, params)
+ end
+ end
+
def authorize(%Plug.Conn{} = conn, params), do: do_authorize(conn, params)
defp do_authorize(%Plug.Conn{} = conn, params) do