Send an identifier alongside with error message in OAuthController
authorMaxim Filippov <colixer@gmail.com>
Tue, 1 Oct 2019 15:10:04 +0000 (18:10 +0300)
committerMaxim Filippov <colixer@gmail.com>
Tue, 1 Oct 2019 15:10:04 +0000 (18:10 +0300)
lib/pleroma/web/oauth/oauth_controller.ex
lib/pleroma/web/translation_helpers.ex
test/web/oauth/oauth_controller_test.exs

index a57670e025f734aa6d6db3ec2cb62cd14a773472..e418dc70d7bc7db486397db43195a8fbd99d2d05 100644 (file)
@@ -212,13 +212,31 @@ defmodule Pleroma.Web.OAuth.OAuthController do
       {:auth_active, false} ->
         # Per https://github.com/tootsuite/mastodon/blob/
         #   51e154f5e87968d6bb115e053689767ab33e80cd/app/controllers/api/base_controller.rb#L76
-        render_error(conn, :forbidden, "Your login is missing a confirmed e-mail address")
+        render_error(
+          conn,
+          :forbidden,
+          "Your login is missing a confirmed e-mail address",
+          %{},
+          "missing_confirmed_email"
+        )
 
       {:user_active, false} ->
-        render_error(conn, :forbidden, "Your account is currently disabled")
+        render_error(
+          conn,
+          :forbidden,
+          "Your account is currently disabled",
+          %{},
+          "account_is_disabled"
+        )
 
       {:password_reset_pending, true} ->
-        render_error(conn, :forbidden, "Password reset is required")
+        render_error(
+          conn,
+          :forbidden,
+          "Password reset is required",
+          %{},
+          "password_reset_required"
+        )
 
       _error ->
         render_invalid_credentials_error(conn)
index 8f5a43bf6e3bbc1dd89742b223da4fdff4ab0af7..7a2ddc00894551dc9c72061bca6a8a47abb1124f 100644 (file)
@@ -3,14 +3,21 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.TranslationHelpers do
-  defmacro render_error(conn, status, msgid, bindings \\ Macro.escape(%{})) do
+  defmacro render_error(
+             conn,
+             status,
+             msgid,
+             bindings \\ Macro.escape(%{}),
+             identifier \\ Macro.escape("")
+           ) do
     quote do
       require Pleroma.Web.Gettext
 
       unquote(conn)
       |> Plug.Conn.put_status(unquote(status))
       |> Phoenix.Controller.json(%{
-        error: Pleroma.Web.Gettext.dgettext("errors", unquote(msgid), unquote(bindings))
+        error: Pleroma.Web.Gettext.dgettext("errors", unquote(msgid), unquote(bindings)),
+        identifier: unquote(identifier)
       })
     end
   end
index 0cf755806ab318db09bb06b41a476385d944f17c..4d0741d14c7d60d7e0d079cf34c215eb650f1508 100644 (file)
@@ -852,6 +852,7 @@ defmodule Pleroma.Web.OAuth.OAuthControllerTest do
       assert resp = json_response(conn, 403)
 
       assert resp["error"] == "Password reset is required"
+      assert resp["identifier"] == "password_reset_required"
       refute Map.has_key?(resp, "access_token")
     end