X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fhelpers%2Fauth_helper.ex;h=13e4c815856294fe585ac91ec22199de4095eeb0;hb=981349f21d401da55168fdb00b245e3dccea1afd;hp=6e29c006a6afc69453ec821cf073512bf753a2a1;hpb=04f6b48ac1a76fe9c6c3fd573427d418bc152adf;p=akkoma
diff --git a/lib/pleroma/helpers/auth_helper.ex b/lib/pleroma/helpers/auth_helper.ex
index 6e29c006a..13e4c8158 100644
--- a/lib/pleroma/helpers/auth_helper.ex
+++ b/lib/pleroma/helpers/auth_helper.ex
@@ -1,9 +1,14 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Helpers.AuthHelper do
alias Pleroma.Web.Plugs.OAuthScopesPlug
+ alias Plug.Conn
+
+ import Plug.Conn
+
+ @oauth_token_session_key :oauth_token
@doc """
Skips OAuth permissions (scopes) checks, assigns nil `:token`.
@@ -11,7 +16,31 @@ defmodule Pleroma.Helpers.AuthHelper do
"""
def skip_oauth(conn) do
conn
- |> Plug.Conn.assign(:token, nil)
+ |> assign(:token, nil)
|> OAuthScopesPlug.skip_plug()
end
+
+ @doc "Drops authentication info from connection"
+ def drop_auth_info(conn) do
+ # To simplify debugging, setting a private variable on `conn` if auth info is dropped
+ conn
+ |> assign(:user, nil)
+ |> assign(:token, nil)
+ |> put_private(:authentication_ignored, true)
+ end
+
+ @doc "Gets OAuth token string from session"
+ def get_session_token(%Conn{} = conn) do
+ get_session(conn, @oauth_token_session_key)
+ end
+
+ @doc "Updates OAuth token string in session"
+ def put_session_token(%Conn{} = conn, token) when is_binary(token) do
+ put_session(conn, @oauth_token_session_key, token)
+ end
+
+ @doc "Deletes OAuth token string from session"
+ def delete_session_token(%Conn{} = conn) do
+ delete_session(conn, @oauth_token_session_key)
+ end
end