aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/web/oauth/oauth_controller.ex
diff options
context:
space:
mode:
authorkaniini <nenolod@gmail.com>2019-05-13 18:35:45 +0000
committerkaniini <nenolod@gmail.com>2019-05-13 18:35:45 +0000
commitf3e8f5b1f208b10130c7123e68af1e38575f180b (patch)
tree523d1f1cfa399f4ee6d841ba3098ecd87d8e67e7 /lib/pleroma/web/oauth/oauth_controller.ex
parent5a4d55cf910f85b07f111972647a8b4410b5eb6b (diff)
parenta2be420f940fb8f181feeb9b0fb9759d433dcae1 (diff)
downloadpleroma-f3e8f5b1f208b10130c7123e68af1e38575f180b.tar.gz
Merge branch 'features/mastoapi/2.7.0-registration' into 'develop'
Features/mastoapi/2.7.0 registration Closes #773 See merge request pleroma/pleroma!1134
Diffstat (limited to 'lib/pleroma/web/oauth/oauth_controller.ex')
-rw-r--r--lib/pleroma/web/oauth/oauth_controller.ex22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex
index 8ee0da667..862b8f8c9 100644
--- a/lib/pleroma/web/oauth/oauth_controller.ex
+++ b/lib/pleroma/web/oauth/oauth_controller.ex
@@ -218,6 +218,28 @@ defmodule Pleroma.Web.OAuth.OAuthController do
token_exchange(conn, params)
end
+ def token_exchange(conn, %{"grant_type" => "client_credentials"} = params) do
+ with %App{} = app <- get_app_from_request(conn, params),
+ {:ok, auth} <- Authorization.create_authorization(app, %User{}),
+ {: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: Enum.join(token.scopes, " ")
+ }
+
+ json(conn, response)
+ else
+ _error ->
+ put_status(conn, 400)
+ |> json(%{error: "Invalid credentials"})
+ end
+ end
+
# Bad request
def token_exchange(conn, params), do: bad_request(conn, params)