2019-02-09 15:09:08 +01: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-15 17:54:37 +01:00
|
|
|
def parse_scopes(scopes, _default) when is_list(scopes) do
|
|
|
|
Enum.filter(scopes, &(&1 not in [nil, ""]))
|
2019-02-13 22:29:29 +01:00
|
|
|
end
|
|
|
|
|
2019-02-14 15:03:19 +01:00
|
|
|
def parse_scopes(scopes, default) when is_binary(scopes) do
|
2019-02-09 15:09:08 +01:00
|
|
|
scopes
|
2019-02-15 17:54:37 +01:00
|
|
|
|> String.trim()
|
2019-02-14 15:03:19 +01:00
|
|
|
|> String.split(~r/[\s,]+/)
|
|
|
|
|> parse_scopes(default)
|
2019-02-13 22:29:29 +01:00
|
|
|
end
|
|
|
|
|
2019-02-14 15:03:19 +01:00
|
|
|
def parse_scopes(_, default) do
|
|
|
|
default
|
2019-02-09 15:09:08 +01:00
|
|
|
end
|
|
|
|
end
|