diff options
author | Roger Braun <roger@rogerbraun.net> | 2017-09-06 19:06:25 +0200 |
---|---|---|
committer | Roger Braun <roger@rogerbraun.net> | 2017-09-06 19:06:25 +0200 |
commit | 2a298d70f9938d1b6d5af04d8b8863fdd3299f46 (patch) | |
tree | 7029989860d19246a0840a7991db46ad5b3207df /lib/pleroma/plugs/oauth_plug.ex | |
parent | 4e785df984bed0e2ffc3f5a773a961ed3efd4760 (diff) | |
download | pleroma-2a298d70f9938d1b6d5af04d8b8863fdd3299f46.tar.gz |
Add very basic oauth and mastodon api support.
Diffstat (limited to 'lib/pleroma/plugs/oauth_plug.ex')
-rw-r--r-- | lib/pleroma/plugs/oauth_plug.ex | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/pleroma/plugs/oauth_plug.ex b/lib/pleroma/plugs/oauth_plug.ex new file mode 100644 index 000000000..fc2a907a2 --- /dev/null +++ b/lib/pleroma/plugs/oauth_plug.ex @@ -0,0 +1,22 @@ +defmodule Pleroma.Plugs.OAuthPlug do + import Plug.Conn + alias Pleroma.User + alias Pleroma.Repo + alias Pleroma.Web.OAuth.Token + + def init(options) do + options + end + + def call(%{assigns: %{user: %User{}}} = conn, _), do: conn + def call(conn, opts) do + with ["Bearer " <> header] <- get_req_header(conn, "authorization"), + %Token{user_id: user_id} <- Repo.get_by(Token, token: header), + %User{} = user <- Repo.get(User, user_id) do + conn + |> assign(:user, user) + else + _ -> conn + end + end +end |