[#468] Prototype of OAuth2 scopes support. TwitterAPI scope restrictions.
This commit is contained in:
parent
99fd199bda
commit
4ad843fb9d
9 changed files with 159 additions and 49 deletions
|
|
@ -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
|
||||
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue