projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix digest mix task on OTP releases
[akkoma]
/
lib
/
pleroma
/
web
/
oauth
/
scopes.ex
diff --git
a/lib/pleroma/web/oauth/scopes.ex
b/lib/pleroma/web/oauth/scopes.ex
index ad9dfb2601b8fcee878247ef37bf58318ff4191d..6f06f1431587388d8c923a3e7ec852314d666b94 100644
(file)
--- a/
lib/pleroma/web/oauth/scopes.ex
+++ b/
lib/pleroma/web/oauth/scopes.ex
@@
-1,5
+1,5
@@
# Pleroma: A lightweight social networking server
# Pleroma: A lightweight social networking server
-# Copyright © 2017-20
19
Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-20
20
Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.OAuth.Scopes do
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.OAuth.Scopes do
@@
-7,15
+7,18
@@
defmodule Pleroma.Web.OAuth.Scopes do
Functions for dealing with scopes.
"""
Functions for dealing with scopes.
"""
+ alias Pleroma.Plugs.OAuthScopesPlug
+
@doc """
@doc """
- Fetch scopes from requ
i
est params.
+ Fetch scopes from request params.
Note: `scopes` is used by Mastodon — supporting it but sticking to
OAuth's standard `scope` wherever we control it
"""
Note: `scopes` is used by Mastodon — supporting it but sticking to
OAuth's standard `scope` wherever we control it
"""
- @spec fetch_scopes(map(), list()) :: list()
+ @spec fetch_scopes(map() | struct(), list()) :: list()
+
def fetch_scopes(params, default) do
def fetch_scopes(params, default) do
- parse_scopes(params["scope"] || params["scopes"], default)
+ parse_scopes(params["scope"] || params["scopes"]
|| params[:scopes]
, default)
end
def parse_scopes(scopes, _default) when is_list(scopes) do
end
def parse_scopes(scopes, _default) when is_list(scopes) do
@@
-53,15
+56,21
@@
defmodule Pleroma.Web.OAuth.Scopes do
@doc """
Validates scopes.
"""
@doc """
Validates scopes.
"""
- @spec validate
s
(list() | nil, list()) ::
+ @spec validate(list() | nil, list()) ::
{:ok, list()} | {:error, :missing_scopes | :unsupported_scopes}
{:ok, list()} | {:error, :missing_scopes | :unsupported_scopes}
- def validate
s([], _app_scopes), do: {:error, :missing_scopes}
-
def validates(nil, _app_scopes),
do: {:error, :missing_scopes}
+ def validate
(blank_scopes, _app_scopes) when blank_scopes in [nil, []],
+
do: {:error, :missing_scopes}
- def validate
s
(scopes, app_scopes) do
- case
scopes -- app_scopes
do
-
[]
-> {:ok, scopes}
+ def validate(scopes, app_scopes) do
+ case
OAuthScopesPlug.filter_descendants(scopes, app_scopes)
do
+
^scopes
-> {:ok, scopes}
_ -> {:error, :unsupported_scopes}
end
end
_ -> {:error, :unsupported_scopes}
end
end
+
+ def contains_admin_scopes?(scopes) do
+ scopes
+ |> OAuthScopesPlug.filter_descendants(["admin"])
+ |> Enum.any?()
+ end
end
end