2018-12-23 21:04:54 +01:00
|
|
|
# Pleroma: A lightweight social networking server
|
2018-12-31 16:41:47 +01:00
|
|
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
2018-12-23 21:04:54 +01:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2017-09-07 08:58:10 +02:00
|
|
|
defmodule Pleroma.Web.OAuth.App do
|
2017-09-06 19:06:25 +02:00
|
|
|
use Ecto.Schema
|
2019-02-09 16:20:18 +01:00
|
|
|
import Ecto.Changeset
|
2017-09-06 19:06:25 +02:00
|
|
|
|
|
|
|
schema "apps" do
|
2018-03-30 15:01:53 +02:00
|
|
|
field(:client_name, :string)
|
|
|
|
field(:redirect_uris, :string)
|
|
|
|
field(:scopes, :string)
|
|
|
|
field(:website, :string)
|
|
|
|
field(:client_id, :string)
|
|
|
|
field(:client_secret, :string)
|
2017-09-06 19:06:25 +02:00
|
|
|
|
|
|
|
timestamps()
|
|
|
|
end
|
|
|
|
|
|
|
|
def register_changeset(struct, params \\ %{}) do
|
2018-03-30 15:01:53 +02:00
|
|
|
changeset =
|
|
|
|
struct
|
|
|
|
|> cast(params, [:client_name, :redirect_uris, :scopes, :website])
|
|
|
|
|> validate_required([:client_name, :redirect_uris, :scopes])
|
2017-09-06 19:06:25 +02:00
|
|
|
|
|
|
|
if changeset.valid? do
|
|
|
|
changeset
|
2019-02-14 02:05:25 +01:00
|
|
|
|> put_change(
|
|
|
|
:client_id,
|
|
|
|
:crypto.strong_rand_bytes(32) |> Base.url_encode64(padding: false)
|
|
|
|
)
|
|
|
|
|> put_change(
|
|
|
|
:client_secret,
|
|
|
|
:crypto.strong_rand_bytes(32) |> Base.url_encode64(padding: false)
|
|
|
|
)
|
2017-09-06 19:06:25 +02:00
|
|
|
else
|
|
|
|
changeset
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|