[#468] Added support for push OAuth scope (Mastodon 2.4+).

This commit is contained in:
Ivan Tashkinov 2019-02-20 17:27:41 +03:00
parent 6fe7acd58e
commit b574d97c2e
3 changed files with 20 additions and 2 deletions

View file

@ -1273,15 +1273,25 @@ def login(conn, _) do
defp get_or_make_app() do defp get_or_make_app() do
find_attrs = %{client_name: @local_mastodon_name, redirect_uris: "."} find_attrs = %{client_name: @local_mastodon_name, redirect_uris: "."}
scopes = ["read", "write", "follow", "push"]
with %App{} = app <- Repo.get_by(App, find_attrs) do with %App{} = app <- Repo.get_by(App, find_attrs) do
{:ok, app} =
if app.scopes == scopes do
{:ok, app}
else
app
|> Ecto.Changeset.change(%{scopes: scopes})
|> Repo.update()
end
{:ok, app} {:ok, app}
else else
_e -> _e ->
cs = cs =
App.register_changeset( App.register_changeset(
%App{}, %App{},
Map.put(find_attrs, :scopes, ["read", "write", "follow"]) Map.put(find_attrs, :scopes, scopes)
) )
Repo.insert(cs) Repo.insert(cs)

View file

@ -93,6 +93,10 @@ defmodule Pleroma.Web.Router do
plug(Pleroma.Plugs.OAuthScopesPlug, %{scopes: ["follow"]}) plug(Pleroma.Plugs.OAuthScopesPlug, %{scopes: ["follow"]})
end end
pipeline :oauth_push do
plug(Pleroma.Plugs.OAuthScopesPlug, %{scopes: ["push"]})
end
pipeline :well_known do pipeline :well_known do
plug(:accepts, ["json", "jrd+json", "xml", "xrd+xml"]) plug(:accepts, ["json", "jrd+json", "xml", "xrd+xml"])
end end
@ -290,6 +294,10 @@ defmodule Pleroma.Web.Router do
post("/domain_blocks", MastodonAPIController, :block_domain) post("/domain_blocks", MastodonAPIController, :block_domain)
delete("/domain_blocks", MastodonAPIController, :unblock_domain) delete("/domain_blocks", MastodonAPIController, :unblock_domain)
end
scope [] do
pipe_through(:oauth_push)
post("/push/subscription", MastodonAPIController, :create_push_subscription) post("/push/subscription", MastodonAPIController, :create_push_subscription)
get("/push/subscription", MastodonAPIController, :get_push_subscription) get("/push/subscription", MastodonAPIController, :get_push_subscription)

View file

@ -214,7 +214,7 @@ def oauth_app_factory do
%Pleroma.Web.OAuth.App{ %Pleroma.Web.OAuth.App{
client_name: "Some client", client_name: "Some client",
redirect_uris: "https://example.com/callback", redirect_uris: "https://example.com/callback",
scopes: ["read", "write", "follow"], scopes: ["read", "write", "follow", "push"],
website: "https://example.com", website: "https://example.com",
client_id: "aaabbb==", client_id: "aaabbb==",
client_secret: "aaa;/&bbb" client_secret: "aaa;/&bbb"