Merge branch 'oauth-mark' into shigusegubu-new
This commit is contained in:
commit
f55eb3a42c
4 changed files with 26 additions and 7 deletions
1
changelog.d/current_token.add
Normal file
1
changelog.d/current_token.add
Normal file
|
|
@ -0,0 +1 @@
|
|||
OAuth token list API now includes property to signify which token is being used to access the API
|
||||
|
|
@ -26,11 +26,11 @@ defmodule Pleroma.Web.OAuth.TokenController do
|
|||
end
|
||||
end
|
||||
|
||||
def oauth_tokens(%{assigns: %{user: user}} = conn, _params) do
|
||||
def oauth_tokens(%{assigns: %{user: user, token: current_token}} = conn, _params) do
|
||||
with oauth_tokens <- Token.get_user_tokens(user) do
|
||||
conn
|
||||
|> put_view(TokenView)
|
||||
|> render("index.json", %{tokens: oauth_tokens})
|
||||
|> render("index.json", %{tokens: oauth_tokens, current_token: current_token})
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -5,18 +5,21 @@
|
|||
defmodule Pleroma.Web.OAuth.TokenView do
|
||||
use Pleroma.Web, :view
|
||||
|
||||
def render("index.json", %{tokens: tokens}) do
|
||||
def render("index.json", %{tokens: tokens, current_token: current_token}) do
|
||||
tokens
|
||||
|> render_many(Pleroma.Web.OAuth.TokenView, "show.json")
|
||||
|> render_many(Pleroma.Web.OAuth.TokenView, "show.json", %{
|
||||
current_token: current_token
|
||||
})
|
||||
|> Enum.filter(&Enum.any?/1)
|
||||
end
|
||||
|
||||
def render("show.json", %{token: token_entry}) do
|
||||
def render("show.json", %{token: token_entry, current_token: current_token}) do
|
||||
%{
|
||||
id: token_entry.id,
|
||||
valid_until: token_entry.valid_until,
|
||||
app_name: token_entry.app.client_name,
|
||||
scopes: token_entry.scopes
|
||||
scopes: token_entry.scopes,
|
||||
is_current_token: token_entry.id == current_token.id
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -62,7 +62,22 @@ defmodule Pleroma.Web.OAuth.TokenControllerTest do
|
|||
|> hd()
|
||||
|> Map.keys()
|
||||
|
||||
assert Enum.sort(keys) == Enum.sort(["id", "app_name", "valid_until", "scopes"])
|
||||
assert Enum.sort(keys) ==
|
||||
Enum.sort(["id", "app_name", "valid_until", "scopes", "is_current_token"])
|
||||
end
|
||||
|
||||
test "marks which token is being used for the request" do
|
||||
%{conn: conn, user: user, token: current} = oauth_access(["read:security"])
|
||||
other = insert(:oauth_token, user: user)
|
||||
|
||||
tokens =
|
||||
conn
|
||||
|> get("/api/oauth_tokens")
|
||||
|> json_response(200)
|
||||
|> Map.new(&{&1["id"], &1["is_current_token"]})
|
||||
|
||||
assert tokens[current.id] == true
|
||||
assert tokens[other.id] == false
|
||||
end
|
||||
|
||||
test "is allowed with the read scope" do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue