action_fallback(Pleroma.Web.OAuth.FallbackController)
def authorize(conn, params) do
+ params_scopes = oauth_scopes(params, nil)
+
+ scopes =
+ if params_scopes do
+ params_scopes
+ else
+ app = Repo.get_by(App, client_id: params["client_id"])
+ app && app.scopes
+ end
+
render(conn, "show.html", %{
response_type: params["response_type"],
client_id: params["client_id"],
- scopes: oauth_scopes(params, []),
+ scopes: scopes || [],
redirect_uri: params["redirect_uri"],
state: params["state"]
})
"password" => password,
"client_id" => client_id,
"redirect_uri" => redirect_uri
- } = params
+ } = auth_params
}) do
with %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)},
%App{} = app <- Repo.get_by(App, client_id: client_id),
true <- redirect_uri in String.split(app.redirect_uris),
- scopes <- oauth_scopes(params, app.scopes),
+ scopes <- oauth_scopes(auth_params, []),
[] <- scopes -- app.scopes,
true <- Enum.any?(scopes),
{:ok, auth} <- Authorization.create_authorization(app, user, scopes) do
url_params = %{:code => auth.token}
url_params =
- if params["state"] do
- Map.put(url_params, :state, params["state"])
+ if auth_params["state"] do
+ Map.put(url_params, :state, auth_params["state"])
else
url_params
end
redirect(conn, external: url)
end
else
- {:auth_active, false} ->
- conn
- |> put_flash(:error, "Account confirmation pending")
- |> put_status(:forbidden)
- |> authorize(params)
+ res ->
+ msg =
+ if res == {:auth_active, false},
+ do: "Account confirmation pending",
+ else: "Invalid Username/Password/Permissions"
+
+ app = Repo.get_by(App, client_id: client_id)
+ available_scopes = (app && app.scopes) || oauth_scopes(auth_params, [])
+ scope_param = Enum.join(available_scopes, " ")
- error ->
- error
+ conn
+ |> put_flash(:error, msg)
+ |> put_status(:unauthorized)
+ |> authorize(Map.merge(auth_params, %{"scope" => scope_param}))
end
end
true <- Pbkdf2.checkpw(password, user.password_hash),
{:auth_active, true} <- {:auth_active, User.auth_active?(user)},
scopes <- oauth_scopes(params, app.scopes),
+ [] <- scopes -- app.scopes,
+ true <- Enum.any?(scopes),
{:ok, auth} <- Authorization.create_authorization(app, user, scopes),
{:ok, token} <- Token.exchange_token(app, auth) do
response = %{
plug(Pleroma.Plugs.EnsureUserKeyPlug)
end
+ pipeline :oauth_read_or_unauthenticated do
+ plug(Pleroma.Plugs.OAuthScopesPlug, %{
+ scopes: ["read"],
+ fallback: :proceed_unauthenticated
+ })
+ end
+
pipeline :oauth_read do
- plug(Pleroma.Plugs.OAuthScopesPlug, %{required_scopes: ["read"]})
+ plug(Pleroma.Plugs.OAuthScopesPlug, %{scopes: ["read"]})
end
pipeline :oauth_write do
- plug(Pleroma.Plugs.OAuthScopesPlug, %{required_scopes: ["write"]})
+ plug(Pleroma.Plugs.OAuthScopesPlug, %{scopes: ["write"]})
end
pipeline :oauth_follow do
- plug(Pleroma.Plugs.OAuthScopesPlug, %{required_scopes: ["follow"]})
+ plug(Pleroma.Plugs.OAuthScopesPlug, %{scopes: ["follow"]})
end
pipeline :well_known do
scope "/api/pleroma", Pleroma.Web.TwitterAPI do
pipe_through(:pleroma_api)
+
get("/password_reset/:token", UtilController, :show_password_reset)
post("/password_reset", UtilController, :password_reset)
get("/emoji", UtilController, :emoji)
end
scope "/api/pleroma/admin", Pleroma.Web.AdminAPI do
- pipe_through(:admin_api)
+ pipe_through([:admin_api, :oauth_write])
+
delete("/user", AdminAPIController, :user_delete)
post("/user", AdminAPIController, :user_create)
put("/users/tag", AdminAPIController, :tag_users)
scope "/", Pleroma.Web.TwitterAPI do
pipe_through(:pleroma_html)
- get("/ostatus_subscribe", UtilController, :remote_follow)
- post("/ostatus_subscribe", UtilController, :do_remote_follow)
+
post("/main/ostatus", UtilController, :remote_subscribe)
+ get("/ostatus_subscribe", UtilController, :remote_follow)
+
+ scope [] do
+ pipe_through(:oauth_follow)
+ post("/ostatus_subscribe", UtilController, :do_remote_follow)
+ end
end
scope "/api/pleroma", Pleroma.Web.TwitterAPI do
scope "/api/v1", Pleroma.Web.MastodonAPI do
pipe_through(:authenticated_api)
- get("/accounts/verify_credentials", MastodonAPIController, :verify_credentials)
-
scope [] do
pipe_through(:oauth_read)
+ get("/accounts/verify_credentials", MastodonAPIController, :verify_credentials)
+
get("/accounts/relationships", MastodonAPIController, :relationships)
get("/accounts/search", MastodonAPIController, :account_search)
scope "/api/v1", Pleroma.Web.MastodonAPI do
pipe_through(:api)
+
get("/instance", MastodonAPIController, :masto_instance)
get("/instance/peers", MastodonAPIController, :peers)
post("/apps", MastodonAPIController, :create_app)
get("/custom_emojis", MastodonAPIController, :custom_emojis)
- get("/timelines/public", MastodonAPIController, :public_timeline)
- get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
- get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
-
- get("/statuses/:id", MastodonAPIController, :get_status)
- get("/statuses/:id/context", MastodonAPIController, :get_context)
get("/statuses/:id/card", MastodonAPIController, :status_card)
+
get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by)
get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by)
- get("/accounts/:id/statuses", MastodonAPIController, :user_statuses)
- get("/accounts/:id/followers", MastodonAPIController, :followers)
- get("/accounts/:id/following", MastodonAPIController, :following)
- get("/accounts/:id", MastodonAPIController, :user)
-
get("/trends", MastodonAPIController, :empty_array)
- get("/search", MastodonAPIController, :search)
+ scope [] do
+ pipe_through(:oauth_read_or_unauthenticated)
+
+ get("/timelines/public", MastodonAPIController, :public_timeline)
+ get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
+ get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
+
+ get("/statuses/:id", MastodonAPIController, :get_status)
+ get("/statuses/:id/context", MastodonAPIController, :get_context)
+
+ get("/accounts/:id/statuses", MastodonAPIController, :user_statuses)
+ get("/accounts/:id/followers", MastodonAPIController, :followers)
+ get("/accounts/:id/following", MastodonAPIController, :following)
+ get("/accounts/:id", MastodonAPIController, :user)
+
+ get("/search", MastodonAPIController, :search)
+ end
end
scope "/api/v2", Pleroma.Web.MastodonAPI do
- pipe_through(:api)
+ pipe_through([:api, :oauth_read_or_unauthenticated])
get("/search", MastodonAPIController, :search2)
end
scope "/api", Pleroma.Web do
pipe_through(:api)
- get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
- get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
- get("/users/show", TwitterAPI.Controller, :show_user)
-
- get("/statuses/followers", TwitterAPI.Controller, :followers)
- get("/statuses/friends", TwitterAPI.Controller, :friends)
- get("/statuses/blocks", TwitterAPI.Controller, :blocks)
- get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
- get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
-
post("/account/register", TwitterAPI.Controller, :register)
post("/account/password_reset", TwitterAPI.Controller, :password_reset)
+ post("/account/resend_confirmation_email", TwitterAPI.Controller, :resend_confirmation_email)
+
get(
"/account/confirm_email/:user_id/:token",
TwitterAPI.Controller,
as: :confirm_email
)
- post("/account/resend_confirmation_email", TwitterAPI.Controller, :resend_confirmation_email)
+ scope [] do
+ pipe_through(:oauth_read_or_unauthenticated)
+
+ get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
+ get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
+ get("/users/show", TwitterAPI.Controller, :show_user)
+
+ get("/statuses/followers", TwitterAPI.Controller, :followers)
+ get("/statuses/friends", TwitterAPI.Controller, :friends)
+ get("/statuses/blocks", TwitterAPI.Controller, :blocks)
+ get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
+ get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
- get("/search", TwitterAPI.Controller, :search)
- get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
+ get("/search", TwitterAPI.Controller, :search)
+ get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
+ end
end
scope "/api", Pleroma.Web do
- pipe_through(:api)
+ pipe_through([:api, :oauth_read_or_unauthenticated])
get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
end
scope "/api", Pleroma.Web, as: :twitter_api_search do
- pipe_through(:api)
+ pipe_through([:api, :oauth_read_or_unauthenticated])
get("/pleroma/search_user", TwitterAPI.Controller, :search_user)
end
scope "/api", Pleroma.Web, as: :authenticated_twitter_api do
pipe_through(:authenticated_api)
- get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
- post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
-
scope [] do
pipe_through(:oauth_read)
+ get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
+ post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
+
get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline)
get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
scope "/", Pleroma.Web.ActivityPub do
pipe_through([:activitypub_client])
- get("/api/ap/whoami", ActivityPubController, :whoami)
- get("/users/:nickname/inbox", ActivityPubController, :read_inbox)
- post("/users/:nickname/outbox", ActivityPubController, :update_outbox)
+ scope [] do
+ pipe_through(:oauth_read)
+ get("/api/ap/whoami", ActivityPubController, :whoami)
+ get("/users/:nickname/inbox", ActivityPubController, :read_inbox)
+ end
+
+ scope [] do
+ pipe_through(:oauth_write)
+ post("/users/:nickname/outbox", ActivityPubController, :update_outbox)
+ end
end
scope "/relay", Pleroma.Web.ActivityPub do
scope "/", Pleroma.Web.ActivityPub do
pipe_through(:activitypub)
+
post("/users/:nickname/inbox", ActivityPubController, :inbox)
post("/inbox", ActivityPubController, :inbox)
end
pipe_through(:mastodon_html)
get("/web/login", MastodonAPIController, :login)
- get("/web/*path", MastodonAPIController, :index)
delete("/auth/sign_out", MastodonAPIController, :logout)
+
+ scope [] do
+ pipe_through(:oauth_read)
+ get("/web/*path", MastodonAPIController, :index)
+ end
end
pipeline :remote_media do
scope "/proxy/", Pleroma.Web.MediaProxy do
pipe_through(:remote_media)
+
get("/:sig/:url", MediaProxyController, :remote)
get("/:sig/:url/:filename", MediaProxyController, :remote)
end