1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Plugs.SessionAuthenticationPlug do
7 Authenticates user by session-stored `:user_id` and request-contained username.
8 Username can be provided via HTTP Basic Auth (the password is not checked and can be anything).
13 alias Pleroma.Helpers.AuthHelper
19 def call(%{assigns: %{user: %Pleroma.User{}}} = conn, _), do: conn
22 with saved_user_id <- get_session(conn, :user_id),
23 %{auth_user: %{id: ^saved_user_id}} <- conn.assigns do
25 |> assign(:user, conn.assigns.auth_user)
26 |> AuthHelper.skip_oauth()