Slight cleanup.
This commit is contained in:
parent
2a298d70f9
commit
2652d9e4ed
8 changed files with 55 additions and 41 deletions
29
lib/pleroma/web/oauth/app.ex
Normal file
29
lib/pleroma/web/oauth/app.ex
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
defmodule Pleroma.Web.OAuth.App do
|
||||
use Ecto.Schema
|
||||
import Ecto.{Changeset}
|
||||
|
||||
schema "apps" do
|
||||
field :client_name, :string
|
||||
field :redirect_uris, :string
|
||||
field :scopes, :string
|
||||
field :website, :string
|
||||
field :client_id, :string
|
||||
field :client_secret, :string
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
def register_changeset(struct, params \\ %{}) do
|
||||
changeset = struct
|
||||
|> cast(params, [:client_name, :redirect_uris, :scopes, :website])
|
||||
|> validate_required([:client_name, :redirect_uris, :scopes])
|
||||
|
||||
if changeset.valid? do
|
||||
changeset
|
||||
|> put_change(:client_id, :crypto.strong_rand_bytes(32) |> Base.url_encode64)
|
||||
|> put_change(:client_secret, :crypto.strong_rand_bytes(32) |> Base.url_encode64)
|
||||
else
|
||||
changeset
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
defmodule Pleroma.Web.OAuth.Authorization do
|
||||
use Ecto.Schema
|
||||
|
||||
alias Pleroma.{App, User, Repo}
|
||||
alias Pleroma.Web.OAuth.Authorization
|
||||
alias Pleroma.{User, Repo}
|
||||
alias Pleroma.Web.OAuth.{Authorization, App}
|
||||
|
||||
schema "oauth_authorizations" do
|
||||
field :token, :string
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
defmodule Pleroma.Web.OAuth.OAuthController do
|
||||
use Pleroma.Web, :controller
|
||||
|
||||
alias Pleroma.Web.OAuth.{Authorization, Token}
|
||||
alias Pleroma.{Repo, User, App}
|
||||
alias Pleroma.Web.OAuth.{Authorization, Token, App}
|
||||
alias Pleroma.{Repo, User}
|
||||
alias Comeonin.Pbkdf2
|
||||
|
||||
def authorize(conn, params) do
|
||||
|
|
@ -17,7 +17,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do
|
|||
def create_authorization(conn, %{"authorization" => %{"name" => name, "password" => password, "client_id" => client_id}} = params) do
|
||||
with %User{} = user <- User.get_cached_by_nickname(name),
|
||||
true <- Pbkdf2.checkpw(password, user.password_hash),
|
||||
%App{} = app <- Pleroma.Repo.get_by(Pleroma.App, client_id: client_id),
|
||||
%App{} = app <- Repo.get_by(App, client_id: client_id),
|
||||
{:ok, auth} <- Authorization.create_authorization(app, user) do
|
||||
render conn, "results.html", %{
|
||||
auth: auth
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
defmodule Pleroma.Web.OAuth.Token do
|
||||
use Ecto.Schema
|
||||
|
||||
alias Pleroma.{App, User, Repo}
|
||||
alias Pleroma.Web.OAuth.Token
|
||||
alias Pleroma.{User, Repo}
|
||||
alias Pleroma.Web.OAuth.{Token, App}
|
||||
|
||||
schema "oauth_tokens" do
|
||||
field :token, :string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue