logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

app.ex (1343B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Mix.Tasks.Pleroma.App do
  5. @moduledoc File.read!("docs/administration/CLI_tasks/oauth_app.md")
  6. use Mix.Task
  7. import Mix.Pleroma
  8. @shortdoc "Creates trusted OAuth App"
  9. def run(["create" | options]) do
  10. start_pleroma()
  11. {opts, _} =
  12. OptionParser.parse!(options,
  13. strict: [name: :string, redirect_uri: :string, scopes: :string],
  14. aliases: [n: :name, r: :redirect_uri, s: :scopes]
  15. )
  16. scopes =
  17. if opts[:scopes] do
  18. String.split(opts[:scopes], ",")
  19. else
  20. ["read", "write", "follow", "push"]
  21. end
  22. params = %{
  23. client_name: opts[:name],
  24. redirect_uris: opts[:redirect_uri],
  25. trusted: true,
  26. scopes: scopes
  27. }
  28. with {:ok, app} <- Pleroma.Web.OAuth.App.create(params) do
  29. shell_info("#{app.client_name} successfully created:")
  30. shell_info("App client_id: " <> app.client_id)
  31. shell_info("App client_secret: " <> app.client_secret)
  32. else
  33. {:error, changeset} ->
  34. shell_error("Creating failed:")
  35. Enum.each(Pleroma.Web.OAuth.App.errors(changeset), fn {key, error} ->
  36. shell_error("#{key}: #{error}")
  37. end)
  38. end
  39. end
  40. end