1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.OAuth.Token.Strategy.Revoke do
7 Functions for dealing with revocation.
11 alias Pleroma.Web.OAuth.App
12 alias Pleroma.Web.OAuth.Token
14 @doc "Finds and revokes access token for app and by token"
15 @spec revoke(App.t(), map()) :: {:ok, Token.t()} | {:error, :not_found | Ecto.Changeset.t()}
16 def revoke(%App{} = app, %{"token" => token} = _attrs) do
17 with {:ok, token} <- Token.get_by_token(app, token),
21 @doc "Revokes access token"
22 @spec revoke(Token.t()) :: {:ok, Token.t()} | {:error, Ecto.Changeset.t()}
23 def revoke(%Token{} = token) do
24 with {:ok, token} <- Repo.delete(token) do
25 Task.Supervisor.start_child(
26 Pleroma.TaskSupervisor,
28 :close_streams_by_oauth_token,