Merge remote-tracking branch 'pleroma/develop' into cycles-views
[akkoma] / lib / pleroma / web / o_auth / o_auth_view.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.OAuth.OAuthView do
6 use Pleroma.Web, :view
7 import Phoenix.HTML.Form
8
9 alias Pleroma.Web.OAuth.Token.Utils
10
11 def render("token.json", %{token: token} = opts) do
12 response = %{
13 id: token.id,
14 token_type: "Bearer",
15 access_token: token.token,
16 refresh_token: token.refresh_token,
17 expires_in: NaiveDateTime.diff(token.valid_until, NaiveDateTime.utc_now()),
18 scope: Enum.join(token.scopes, " "),
19 created_at: Utils.format_created_at(token)
20 }
21
22 if user = opts[:user] do
23 response
24 |> Map.put(:me, user.ap_id)
25 else
26 response
27 end
28 end
29 end