Merge branch 'fix/sign-in-with-toot' into 'develop'
authorHaelwenn <git.pleroma.social@hacktivis.me>
Wed, 5 Sep 2018 18:20:26 +0000 (18:20 +0000)
committerHaelwenn <git.pleroma.social@hacktivis.me>
Wed, 5 Sep 2018 18:20:26 +0000 (18:20 +0000)
Fix sign-in and sign-out with Toot!

See merge request pleroma/pleroma!306

lib/pleroma/web/mastodon_api/views/account_view.ex
lib/pleroma/web/oauth/oauth_controller.ex
lib/pleroma/web/router.ex
test/web/mastodon_api/account_view_test.exs

index 85aac493f809a1db8a47110ea1f8b5ea9633f853..e206e64865c833c17fd9571bbbb79f1bfcebc22a 100644 (file)
@@ -54,7 +54,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
       source: %{
         note: "",
         privacy: user_info.default_scope,
-        sensitive: "false"
+        sensitive: false
       }
     }
   end
index a5fb32a4e774752c27537598f135470e71d59482..160cedd8ee304f3ab103e9097a630ea9fcbfa2f3 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"
       }
@@ -116,6 +118,18 @@ defmodule Pleroma.Web.OAuth.OAuthController do
     token_exchange(conn, params)
   end
 
+  def token_revoke(conn, %{"token" => token} = params) do
+    with %App{} = app <- get_app_from_request(conn, params),
+         %Token{} = token <- Repo.get_by(Token, token: token, app_id: app.id),
+         {:ok, %Token{}} <- Repo.delete(token) do
+      json(conn, %{})
+    else
+      _error ->
+        # RFC 7009: invalid tokens [in the request] do not cause an error response
+        json(conn, %{})
+    end
+  end
+
   defp fix_padding(token) do
     token
     |> Base.url_decode64!(padding: false)
index b212a29095345c119846e2611a501f53e75f660e..63493ae1cb41b3fadbfdf60f6ba7d4987d6dfbc8 100644 (file)
@@ -93,6 +93,7 @@ defmodule Pleroma.Web.Router do
     get("/authorize", OAuthController, :authorize)
     post("/authorize", OAuthController, :create_authorization)
     post("/token", OAuthController, :token_exchange)
+    post("/revoke", OAuthController, :token_revoke)
   end
 
   scope "/api/v1", Pleroma.Web.MastodonAPI do
index 5393732eb1637806ca6f4ec7b725aa28509f506b..b0e63df0ed0b86f0488dd0db406251976ce5b3b5 100644 (file)
@@ -90,7 +90,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
       source: %{
         note: "",
         privacy: "public",
-        sensitive: "false"
+        sensitive: false
       }
     }