aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/web/oauth/oauth_controller.ex
diff options
context:
space:
mode:
authorIvan Tashkinov <ivantashkinov@gmail.com>2019-02-09 17:09:08 +0300
committerIvan Tashkinov <ivantashkinov@gmail.com>2019-02-09 17:09:08 +0300
commit4ad843fb9df838f36c014ddfb76d7107ba2b5c7b (patch)
tree661ff9cb6e6cdadfdf8e980841f8d11b315df56a /lib/pleroma/web/oauth/oauth_controller.ex
parent99fd199bda8bd90cd3e8c69d54087531ddc02eac (diff)
downloadpleroma-4ad843fb9df838f36c014ddfb76d7107ba2b5c7b.tar.gz
[#468] Prototype of OAuth2 scopes support. TwitterAPI scope restrictions.
Diffstat (limited to 'lib/pleroma/web/oauth/oauth_controller.ex')
-rw-r--r--lib/pleroma/web/oauth/oauth_controller.ex12
1 files changed, 4 insertions, 8 deletions
diff --git a/lib/pleroma/web/oauth/oauth_controller.ex b/lib/pleroma/web/oauth/oauth_controller.ex
index 8ec963c79..15345d4ba 100644
--- a/lib/pleroma/web/oauth/oauth_controller.ex
+++ b/lib/pleroma/web/oauth/oauth_controller.ex
@@ -38,7 +38,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do
{:auth_active, true} <- {:auth_active, User.auth_active?(user)},
%App{} = app <- Repo.get_by(App, client_id: client_id),
true <- redirect_uri in String.split(app.redirect_uris),
- {:ok, auth} <- Authorization.create_authorization(app, user) do
+ {:ok, auth} <- Authorization.create_authorization(app, user, params["scope"]) do
# Special case: Local MastodonFE.
redirect_uri =
if redirect_uri == "." do
@@ -81,8 +81,6 @@ defmodule Pleroma.Web.OAuth.OAuthController do
end
end
- # TODO
- # - proper scope handling
def token_exchange(conn, %{"grant_type" => "authorization_code"} = params) do
with %App{} = app <- get_app_from_request(conn, params),
fixed_token = fix_padding(params["code"]),
@@ -96,7 +94,7 @@ defmodule Pleroma.Web.OAuth.OAuthController do
refresh_token: token.refresh_token,
created_at: DateTime.to_unix(inserted_at),
expires_in: 60 * 10,
- scope: "read write follow"
+ scope: token.scope
}
json(conn, response)
@@ -107,8 +105,6 @@ defmodule Pleroma.Web.OAuth.OAuthController do
end
end
- # TODO
- # - investigate a way to verify the user wants to grant read/write/follow once scope handling is done
def token_exchange(
conn,
%{"grant_type" => "password", "username" => name, "password" => password} = params
@@ -117,14 +113,14 @@ defmodule Pleroma.Web.OAuth.OAuthController do
%User{} = user <- User.get_by_nickname_or_email(name),
true <- Pbkdf2.checkpw(password, user.password_hash),
{:auth_active, true} <- {:auth_active, User.auth_active?(user)},
- {:ok, auth} <- Authorization.create_authorization(app, user),
+ {:ok, auth} <- Authorization.create_authorization(app, user, params["scope"]),
{:ok, token} <- Token.exchange_token(app, auth) do
response = %{
token_type: "Bearer",
access_token: token.token,
refresh_token: token.refresh_token,
expires_in: 60 * 10,
- scope: "read write follow"
+ scope: token.scope
}
json(conn, response)