OAuth: Set `created_at` in token exchange response
authorMartin Kühl <martin.kuehl@gmail.com>
Tue, 28 Aug 2018 23:07:17 +0000 (01:07 +0200)
committerMartin Kühl <martin.kuehl@gmail.com>
Sat, 1 Sep 2018 21:10:48 +0000 (23:10 +0200)
(for compatibility with Mastodon)

lib/pleroma/web/oauth/oauth_controller.ex

index a5fb32a4e774752c27537598f135470e71d59482..934171585ecead6b9f98f2b80fdacfd87a76047a 100644 (file)
@@ -60,11 +60,13 @@ defmodule Pleroma.Web.OAuth.OAuthController do
          fixed_token = fix_padding(params["code"]),
          %Authorization{} = auth <-
            Repo.get_by(Authorization, token: fixed_token, app_id: app.id),
-         {:ok, token} <- Token.exchange_token(app, auth) do
+         {:ok, token} <- Token.exchange_token(app, auth),
+         {:ok, inserted_at} <- DateTime.from_naive(token.inserted_at, "Etc/UTC") do
       response = %{
         token_type: "Bearer",
         access_token: token.token,
         refresh_token: token.refresh_token,
+        created_at: DateTime.to_unix(inserted_at),
         expires_in: 60 * 10,
         scope: "read write follow"
       }