logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

auth_helper.ex (1377B)


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