d56f6f46141a46ac669b6429d4c1a47d8568270d
[akkoma] / lib / pleroma / helpers / auth_helper.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Helpers.AuthHelper do
6 alias Pleroma.Web.Plugs.OAuthScopesPlug
7
8 import Plug.Conn
9
10 @doc """
11 Skips OAuth permissions (scopes) checks, assigns nil `:token`.
12 Intended to be used with explicit authentication and only when OAuth token cannot be determined.
13 """
14 def skip_oauth(conn) do
15 conn
16 |> assign(:token, nil)
17 |> OAuthScopesPlug.skip_plug()
18 end
19
20 @doc "Drops authentication info from connection"
21 def drop_auth_info(conn) do
22 # To simplify debugging, setting a private variable on `conn` if auth info is dropped
23 conn
24 |> assign(:user, nil)
25 |> assign(:token, nil)
26 |> put_private(:authentication_ignored, true)
27 end
28 end