|> Repo.delete_all()
end
- def get_user_tokens(%User{id: user_id}) do
+ def delete_user_token(%User{id: user_id}, token_id) do
from(
t in Pleroma.Web.OAuth.Token,
+ where: t.user_id == ^user_id,
+ where: t.id == ^token_id
+ )
+ |> Repo.delete_all()
+ end
+
+ def get_user_tokens(%User{id: user_id}) do
+ from(
+ t in Token,
where: t.user_id == ^user_id
)
|> Repo.all()
get("/externalprofile/show", TwitterAPI.Controller, :external_profile)
get("/oauth_tokens", TwitterAPI.Controller, :oauth_tokens)
+ delete("/oauth_tokens/:id", TwitterAPI.Controller, :revoke_token)
end
pipeline :ap_relay do
end
end
+ def revoke_token(%{assigns: %{user: user}} = conn, %{"id" => id} = _params) do
+ Token.delete_user_token(user, id)
+
+ json_reply(conn, 201, "")
+ end
+
def blocks(%{assigns: %{user: user}} = conn, _params) do
with blocked_users <- User.blocked_users(user) do
conn
alias Pleroma.Builders.{ActivityBuilder, UserBuilder}
alias Pleroma.{Repo, Activity, User, Object, Notification}
alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Web.OAuth.Token
alias Pleroma.Web.TwitterAPI.UserView
alias Pleroma.Web.TwitterAPI.NotificationView
alias Pleroma.Web.CommonAPI
end
describe "GET /api/oauth_tokens" do
- test "renders list" do
- token = insert(:oauth_token)
+ setup do
+ token = insert(:oauth_token) |> Repo.preload(:user)
+
+ %{token: token}
+ end
+ test "renders list", %{token: token} do
response =
build_conn()
- |> assign(:user, Repo.get(User, token.user_id))
+ |> assign(:user, token.user)
|> get("/api/oauth_tokens")
keys =
assert keys -- ["id", "refresh_token", "token", "valid_until"] == []
end
+
+ test "revoke token", %{token: token} do
+ response =
+ build_conn()
+ |> assign(:user, token.user)
+ |> delete("/api/oauth_tokens/#{token.id}")
+
+ tokens = Token.get_user_tokens(token.user)
+
+ assert tokens == []
+ assert response.status == 201
+ end
end
end