oauth: support either name or username parameter with grant_type=password
authorWilliam Pitcock <nenolod@dereferenced.org>
Thu, 14 Jun 2018 01:45:10 +0000 (01:45 +0000)
committerWilliam Pitcock <nenolod@dereferenced.org>
Thu, 14 Jun 2018 02:07:43 +0000 (02:07 +0000)
closes #180

lib/pleroma/web/oauth/oauth_controller.ex

index 3dd87d0ab9d7ea716ec7af8b32a59e2dc98d5e11..cdfae8b6ae444e64fbcfe1fd119e97c278cf0247 100644 (file)
@@ -81,7 +81,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do
   # - investigate a way to verify the user wants to grant read/write/follow once scope handling is done
   def token_exchange(
         conn,
-        %{"grant_type" => "password", "name" => name, "password" => password} = params
+        %{"grant_type" => "password", "username" => name, "password" => password} = params
       ) do
     with %App{} = app <- get_app_from_request(conn, params),
          %User{} = user <- User.get_cached_by_nickname(name),
@@ -104,6 +104,18 @@ defmodule Pleroma.Web.OAuth.OAuthController do
     end
   end
 
+  def token_exchange(
+        conn,
+        %{"grant_type" => "password", "name" => name, "password" => password} = params
+      ) do
+    params =
+      params
+      |> Map.delete("name")
+      |> Map.put("username", name)
+
+    token_exchange(conn, params)
+  end
+
   defp fix_padding(token) do
     token
     |> Base.url_decode64!(padding: false)