diff options
author | Alex Gleason <alex@alexgleason.me> | 2020-07-19 19:37:54 -0500 |
---|---|---|
committer | Alex Gleason <alex@alexgleason.me> | 2020-07-19 19:37:54 -0500 |
commit | d11c0ede3a2f8ffbca23e7382296cd9125f1365d (patch) | |
tree | 6123951765bcdecaf5ed5597e98551619aea03f9 /lib/pleroma/web/oauth/oauth_controller.ex | |
parent | 9f48dfb70515b1548f0b30e6c7dbe1776b0d9435 (diff) | |
download | pleroma-d11c0ede3a2f8ffbca23e7382296cd9125f1365d.tar.gz |
Let the OAuth form remember you, fixes #1909
Diffstat (limited to 'lib/pleroma/web/oauth/oauth_controller.ex')
-rw-r--r-- | lib/pleroma/web/oauth/oauth_controller.ex | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex index 7683589cf..5c93f96f1 100644 --- a/lib/pleroma/web/oauth/oauth_controller.ex +++ b/lib/pleroma/web/oauth/oauth_controller.ex @@ -76,8 +76,17 @@ defmodule Pleroma.Web.OAuth.OAuthController do available_scopes = (app && app.scopes) || [] scopes = Scopes.fetch_scopes(params, available_scopes) + user = + with %{assigns: %{user: %User{} = user}} <- conn do + user + else + _ -> nil + end + # Note: `params` might differ from `conn.params`; use `@params` not `@conn.params` in template render(conn, Authenticator.auth_template(), %{ + app: app && Map.delete(app, :client_secret), + user: user, response_type: params["response_type"], client_id: params["client_id"], available_scopes: available_scopes, @@ -121,11 +130,13 @@ defmodule Pleroma.Web.OAuth.OAuthController do end end - def create_authorization( - %Plug.Conn{} = conn, - %{"authorization" => _} = params, - opts \\ [] - ) do + def create_authorization(_, _, opts \\ []) + + def create_authorization(%Plug.Conn{assigns: %{user: %User{} = user}} = conn, params, []) do + create_authorization(conn, params, user: user) + end + + def create_authorization(%Plug.Conn{} = conn, %{"authorization" => _} = params, opts) do with {:ok, auth, user} <- do_create_authorization(conn, params, opts[:user]), {:mfa_required, _, _, false} <- {:mfa_required, user, auth, MFA.require?(user)} do after_create_authorization(conn, auth, params) |