Do oauth redirect.
authorRoger Braun <roger@rogerbraun.net>
Sat, 9 Sep 2017 17:03:57 +0000 (19:03 +0200)
committerRoger Braun <roger@rogerbraun.net>
Sat, 9 Sep 2017 17:03:57 +0000 (19:03 +0200)
lib/pleroma/web/oauth/oauth_controller.ex

index 579d6b3f4960495c46cc39f2d27715dba0c70da5..4672ce00ef9da24c3a4bafccaf926b7a06247842 100644 (file)
@@ -14,14 +14,19 @@ defmodule Pleroma.Web.OAuth.OAuthController do
     }
   end
 
-  def create_authorization(conn, %{"authorization" => %{"name" => name, "password" => password, "client_id" => client_id}} = params) do
+  def create_authorization(conn, %{"authorization" => %{"name" => name, "password" => password, "client_id" => client_id, "redirect_uri" => redirect_uri}} = params) do
     with %User{} = user <- User.get_cached_by_nickname(name),
          true <- Pbkdf2.checkpw(password, user.password_hash),
          %App{} = app <- Repo.get_by(App, client_id: client_id),
          {:ok, auth} <- Authorization.create_authorization(app, user) do
-      render conn, "results.html", %{
-        auth: auth
-      }
+      if redirect_uri == "urn:ietf:wg:oauth:2.0:oob" do
+        render conn, "results.html", %{
+          auth: auth
+        }
+      else
+        url = "#{redirect_uri}?code=#{auth.token}"
+        redirect(conn, external: url)
+      end
     end
   end