1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Helpers.AuthHelper do
6 alias Pleroma.Web.Plugs.OAuthScopesPlug
11 @oauth_token_session_key :oauth_token
14 Skips OAuth permissions (scopes) checks, assigns nil `:token`.
15 Intended to be used with explicit authentication and only when OAuth token cannot be determined.
17 def skip_oauth(conn) do
19 |> assign(:token, nil)
20 |> OAuthScopesPlug.skip_plug()
23 @doc "Drops authentication info from connection"
24 def drop_auth_info(conn) do
25 # To simplify debugging, setting a private variable on `conn` if auth info is dropped
28 |> assign(:token, nil)
29 |> put_private(:authentication_ignored, true)
32 @doc "Gets OAuth token string from session"
33 def get_session_token(%Conn{} = conn) do
34 get_session(conn, @oauth_token_session_key)
37 @doc "Updates OAuth token string in session"
38 def put_session_token(%Conn{} = conn, token) when is_binary(token) do
39 put_session(conn, @oauth_token_session_key, token)
42 @doc "Deletes OAuth token string from session"
43 def delete_session_token(%Conn{} = conn) do
44 delete_session(conn, @oauth_token_session_key)