[#468] Prototype of OAuth2 scopes support. TwitterAPI scope restrictions.

This commit is contained in:
Ivan Tashkinov 2019-02-09 17:09:08 +03:00
commit 4ad843fb9d
9 changed files with 159 additions and 49 deletions

View file

@ -0,0 +1,11 @@
defmodule Pleroma.Repo.Migrations.AddScopeToOAuthEntities do
use Ecto.Migration
def change do
for t <- [:oauth_authorizations, :oauth_tokens] do
alter table(t) do
add :scope, :string
end
end
end
end

View file

@ -0,0 +1,29 @@
defmodule Pleroma.Repo.Migrations.DataMigrationPopulateOAuthScope do
use Ecto.Migration
require Ecto.Query
alias Ecto.Query
alias Pleroma.Repo
alias Pleroma.Web.OAuth
alias Pleroma.Web.OAuth.{App, Authorization, Token}
def up do
for app <- Repo.all(Query.from(app in App)) do
scopes = OAuth.parse_scopes(app.scopes)
scope = Enum.join(scopes, " ")
Repo.update_all(
Query.from(auth in Authorization, where: auth.app_id == ^app.id),
set: [scope: scope]
)
Repo.update_all(
Query.from(token in Token, where: token.app_id == ^app.id),
set: [scope: scope]
)
end
end
def down, do: :noop
end