Merge branch 'develop' of https://git.pleroma.social/pleroma/pleroma into develop
[akkoma] / lib / pleroma / plugs / basic_auth_decoder_plug.ex
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
5 defmodule Pleroma.Plugs.BasicAuthDecoderPlug do
6 import Plug.Conn
7
8 def init(options) do
9 options
10 end
11
12 def call(conn, _opts) do
13 with ["Basic " <> header] <- get_req_header(conn, "authorization"),
14 {:ok, userinfo} <- Base.decode64(header),
15 [username, password] <- String.split(userinfo, ":", parts: 2) do
16 conn
17 |> assign(:auth_credentials, %{
18 username: username,
19 password: password
20 })
21 else
22 _ -> conn
23 end
24 end
25 end