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.OAuth.Token.Response do
10 alias Pleroma.Web.OAuth.Token.Utils
13 def build(%User{} = user, token, opts \\ %{}) do
16 access_token: token.token,
17 refresh_token: token.refresh_token,
18 expires_in: expires_in(),
19 scope: Enum.join(token.scopes, " "),
25 def build_for_client_credentials(token) do
28 access_token: token.token,
29 refresh_token: token.refresh_token,
30 created_at: Utils.format_created_at(token),
31 expires_in: expires_in(),
32 scope: Enum.join(token.scopes, " ")
36 def build_for_mfa_token(user, mfa_token) do
38 error: "mfa_required",
39 mfa_token: mfa_token.token,
40 supported_challenge_types: MFA.supported_methods(user)
44 defp expires_in, do: Pleroma.Config.get([:oauth2, :token_expires_in], 600)