1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Auth.Helpers do
8 @doc "Gets user by nickname or email for auth."
9 @spec fetch_user(String.t()) :: User.t() | nil
10 def fetch_user(name) do
11 User.get_by_nickname_or_email(name)
14 # Gets name and password from conn
16 @spec fetch_credentials(Plug.Conn.t() | map()) ::
17 {:ok, {name :: any, password :: any}} | {:error, :invalid_credentials}
18 def fetch_credentials(%Plug.Conn{params: params} = _),
19 do: fetch_credentials(params)
21 def fetch_credentials(params) do
23 %{"authorization" => %{"name" => name, "password" => password}} ->
24 {:ok, {name, password}}
26 %{"grant_type" => "password", "username" => name, "password" => password} ->
27 {:ok, {name, password}}
30 {:error, :invalid_credentials}