Fix oauth2 (for real) (#179)
[akkoma] / lib / pleroma / web / o_auth / token.ex
index 886117d155fe5b1ed2d2cd908fc2994db8d0cb15..6e91b62166768a8d7f5386e78a8b9cdf02236728 100644 (file)
@@ -1,5 +1,5 @@
 # Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Web.OAuth.Token do
@@ -39,6 +39,12 @@ defmodule Pleroma.Web.OAuth.Token do
     |> Repo.find_resource()
   end
 
+  def get_preexisting_by_app_and_user(%App{} = app, %User{} = user) do
+    app.id
+    |> Query.get_unexpired_by_app_and_user(user)
+    |> Repo.find_resource()
+  end
+
   @doc "Gets token for app by access token"
   @spec get_by_token(App.t(), String.t()) :: {:ok, t()} | {:error, :not_found}
   def get_by_token(%App{id: app_id} = _app, token) do