aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/web/oauth
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pleroma/web/oauth')
-rw-r--r--lib/pleroma/web/oauth/oauth_controller.ex3
-rw-r--r--lib/pleroma/web/oauth/token.ex3
-rw-r--r--lib/pleroma/web/oauth/token/clean_worker.ex26
3 files changed, 12 insertions, 20 deletions
diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex
index ef53b7ae3..81eae2c8b 100644
--- a/lib/pleroma/web/oauth/oauth_controller.ex
+++ b/lib/pleroma/web/oauth/oauth_controller.ex
@@ -365,8 +365,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do
def register(%Plug.Conn{} = conn, %{"authorization" => _, "op" => "connect"} = params) do
with registration_id when not is_nil(registration_id) <- get_session_registration_id(conn),
%Registration{} = registration <- Repo.get(Registration, registration_id),
- {_, {:ok, auth}} <-
- {:create_authorization, do_create_authorization(conn, params)},
+ {_, {:ok, auth}} <- {:create_authorization, do_create_authorization(conn, params)},
%User{} = user <- Repo.preload(auth, :user).user,
{:ok, _updated_registration} <- Registration.bind_to_user(registration, user) do
conn
diff --git a/lib/pleroma/web/oauth/token.ex b/lib/pleroma/web/oauth/token.ex
index 90c304487..40f131b57 100644
--- a/lib/pleroma/web/oauth/token.ex
+++ b/lib/pleroma/web/oauth/token.ex
@@ -44,8 +44,7 @@ defmodule Pleroma.Web.OAuth.Token do
|> Repo.find_resource()
end
- @spec exchange_token(App.t(), Authorization.t()) ::
- {:ok, Token.t()} | {:error, Changeset.t()}
+ @spec exchange_token(App.t(), Authorization.t()) :: {:ok, Token.t()} | {:error, Changeset.t()}
def exchange_token(app, auth) do
with {:ok, auth} <- Authorization.use_token(auth),
true <- auth.app_id == app.id do
diff --git a/lib/pleroma/web/oauth/token/clean_worker.ex b/lib/pleroma/web/oauth/token/clean_worker.ex
index dca852449..f50098302 100644
--- a/lib/pleroma/web/oauth/token/clean_worker.ex
+++ b/lib/pleroma/web/oauth/token/clean_worker.ex
@@ -6,36 +6,30 @@ defmodule Pleroma.Web.OAuth.Token.CleanWorker do
@moduledoc """
The module represents functions to clean an expired oauth tokens.
"""
+ use GenServer
+
+ @ten_seconds 10_000
+ @one_day 86_400_000
- # 10 seconds
- @start_interval 10_000
@interval Pleroma.Config.get(
- # 24 hours
[:oauth2, :clean_expired_tokens_interval],
- 86_400_000
+ @one_day
)
- @queue :background
alias Pleroma.Web.OAuth.Token
- def start_link, do: GenServer.start_link(__MODULE__, nil)
+ def start_link(_), do: GenServer.start_link(__MODULE__, %{})
def init(_) do
- if Pleroma.Config.get([:oauth2, :clean_expired_tokens], false) do
- Process.send_after(self(), :perform, @start_interval)
- {:ok, nil}
- else
- :ignore
- end
+ Process.send_after(self(), :perform, @ten_seconds)
+ {:ok, nil}
end
@doc false
def handle_info(:perform, state) do
+ Token.delete_expired_tokens()
+
Process.send_after(self(), :perform, @interval)
- PleromaJobQueue.enqueue(@queue, __MODULE__, [:clean])
{:noreply, state}
end
-
- # Job Worker Callbacks
- def perform(:clean), do: Token.delete_expired_tokens()
end