1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.Plugs.EnsurePublicOrAuthenticatedPlug do
7 Ensures instance publicity or _user_ authentication
8 (app-bound user-unbound tokens are accepted only if the instance is public).
11 import Pleroma.Web.TranslationHelpers
17 use Pleroma.Web, :plug
24 def perform(conn, _) do
25 public? = Config.get!([:instance, :public])
27 case {public?, conn} do
31 {false, %{assigns: %{user: %User{}}}} ->
36 |> render_error(:forbidden, "This resource requires authentication.")