2019-02-09 14:09:08 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.OAuth do
|
2019-02-14 14:03:19 +00:00
|
|
|
def parse_scopes(scopes, default) when is_list(scopes) do
|
|
|
|
scopes = Enum.filter(scopes, &(&1 not in [nil, ""]))
|
|
|
|
|
|
|
|
if Enum.any?(scopes),
|
|
|
|
do: scopes,
|
|
|
|
else: default
|
2019-02-13 21:29:29 +00:00
|
|
|
end
|
|
|
|
|
2019-02-14 14:03:19 +00:00
|
|
|
def parse_scopes(scopes, default) when is_binary(scopes) do
|
2019-02-09 14:09:08 +00:00
|
|
|
scopes
|
2019-02-14 14:03:19 +00:00
|
|
|
|> String.split(~r/[\s,]+/)
|
|
|
|
|> parse_scopes(default)
|
2019-02-13 21:29:29 +00:00
|
|
|
end
|
|
|
|
|
2019-02-14 14:03:19 +00:00
|
|
|
def parse_scopes(_, default) do
|
|
|
|
default
|
2019-02-09 14:09:08 +00:00
|
|
|
end
|
|
|
|
end
|