logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

basic_auth_decoder_plug.ex (649B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Plugs.BasicAuthDecoderPlug do
  5. import Plug.Conn
  6. def init(options) do
  7. options
  8. end
  9. def call(conn, _opts) do
  10. with ["Basic " <> header] <- get_req_header(conn, "authorization"),
  11. {:ok, userinfo} <- Base.decode64(header),
  12. [username, password] <- String.split(userinfo, ":", parts: 2) do
  13. conn
  14. |> assign(:auth_credentials, %{
  15. username: username,
  16. password: password
  17. })
  18. else
  19. _ -> conn
  20. end
  21. end
  22. end