Mark currently accessing token in oauth token management API #8059

Merged
hj merged 6 commits from oauth-mark into develop 2026-11-05 16:38:21 +00:00
Member

Essential thing for when managing your access tokens. Otherwise it's extremely easy to revoke your own token and accidentaly log yourself out.

Checklist

  • Adding a changelog: In the changelog.d directory, create a file named <code>.<type>.
Essential thing for when managing your access tokens. Otherwise it's extremely easy to revoke your own token and accidentaly log yourself out. ### Checklist - [x] Adding a changelog: In the `changelog.d` directory, create a file named `<code>.<type>`. <!-- `<code>` can be anything, but we recommend using a more or less unique identifier to avoid collisions, such as the branch name. `<type>` can be `add`, `change`, `remove`, `fix`, `security` or `skip`. `skip` is only used if there is no user-visible change in the PR (for example, only editing comments in the code). Otherwise, choose a type that corresponds to your change. In the file, write the changelog entry. For example, if a PR adds group functionality, we can create a file named `group.add` and write `Add group functionality` in it. If one changelog entry is not enough, you may add more. But that might mean you can split it into two PRs. Only use more than one changelog entry if you really need to (for example, when one change in the code fix two different bugs, or when refactoring). -->
Mark currently accessing token in oauth token management API
Some checks failed
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline failed
ci/woodpecker/pr/unit-testing-elixir-1.17 Pipeline was skipped
ci/woodpecker/pr/unit-testing-elixir-1.19 Pipeline was skipped
bcc8b1e296
mix format
Some checks failed
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline failed
ci/woodpecker/pr/unit-testing-elixir-1.17 Pipeline was skipped
ci/woodpecker/pr/unit-testing-elixir-1.19 Pipeline was skipped
573134ac6c
Revert "mix format"
Some checks failed
ci/woodpecker/pr/unit-testing-elixir-1.17 Pipeline is pending
ci/woodpecker/pr/unit-testing-elixir-1.19 Pipeline is pending
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline was canceled
dfc21dc124
This reverts commit 573134ac6c.
manual lint
Some checks failed
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.17 Pipeline failed
ci/woodpecker/pr/unit-testing-elixir-1.19 Pipeline failed
22a2890f2b
oops?
All checks were successful
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.17 Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.19 Pipeline was successful
a614fcba79
Author
Member

/oc review

/oc review
opencode-fix-bot requested changes 2026-11-05 15:26:02 +00:00
Dismissed
opencode-fix-bot left a comment

opencode-agent:job=171:generation=1

Verdict

GET /api/oauth_tokens returns 500 for every request on this head. I ran test/pleroma/web/o_auth/token_controller_test.exs against the exact head commit: 11 tests, 3 failures — every test that hits the list endpoint fails with Phoenix.Template.UndefinedError (Assigned keys: [:user, :tokens, :token, ...]).

P1: current_token assign never reaches the view, so the endpoint always 500s

Two halves of one root cause:

  • lib/pleroma/web/o_auth/token_controller.ex:33 renders with the key token:, but the "index.json" clause in lib/pleroma/web/o_auth/token_view.ex:8 matches on current_token:. No clause matches, so rendering raises and the action fallback returns 500.
  • Even past that, token_view.ex:10 calls render_many(Pleroma.Web.OAuth.TokenView, "show.json") with no extra assigns, so each item is rendered with only %{token: entry} — while the "show.json" clause in token_view.ex:14 requires %{token: _, current_token: _} and would raise the same way one level down.

Triggering conditions: any GET /api/oauth_tokens with a valid token; the pre-existing "renders list" and "is allowed with the read scope" tests fail along with the new "marks which token is being used for the request" test. Impact: the token-management list (the page this PR exists to improve) is completely unusable, and the new is_current_token field never renders.

Smallest correction:

# lib/pleroma/web/o_auth/token_controller.ex
|> render("index.json", %{tokens: oauth_tokens, current_token: current_token})
# lib/pleroma/web/o_auth/token_view.ex
def render("index.json", %{tokens: tokens, current_token: current_token}) do
  tokens
  |> render_many(Pleroma.Web.OAuth.TokenView, "show.json", %{current_token: current_token})
  |> Enum.filter(&Enum.any?/1)
end

Checked and not raised

  • Nil-token path: OAuthScopesPlug halts with 403 before the action when the token assign is nil, so current_token.id cannot see nil here.
  • No other callers render TokenView, and the new test itself plus the changelog entry look fine once the plumbing is fixed.

Merge readiness: 2/5

One P1 finding (caps the rating at 3/5): the PR's entire feature and the pre-existing list endpoint are broken, but the scope is narrow and the fix above is small. Re-run the token controller tests after fixing.

opencode-agent:job=171:generation=1 ### Verdict `GET /api/oauth_tokens` returns 500 for every request on this head. I ran `test/pleroma/web/o_auth/token_controller_test.exs` against the exact head commit: 11 tests, 3 failures — every test that hits the list endpoint fails with `Phoenix.Template.UndefinedError` (`Assigned keys: [:user, :tokens, :token, ...]`). ### P1: `current_token` assign never reaches the view, so the endpoint always 500s Two halves of one root cause: - `lib/pleroma/web/o_auth/token_controller.ex:33` renders with the key `token:`, but the `"index.json"` clause in `lib/pleroma/web/o_auth/token_view.ex:8` matches on `current_token:`. No clause matches, so rendering raises and the action fallback returns 500. - Even past that, `token_view.ex:10` calls `render_many(Pleroma.Web.OAuth.TokenView, "show.json")` with no extra assigns, so each item is rendered with only `%{token: entry}` — while the `"show.json"` clause in `token_view.ex:14` requires `%{token: _, current_token: _}` and would raise the same way one level down. Triggering conditions: any `GET /api/oauth_tokens` with a valid token; the pre-existing `"renders list"` and `"is allowed with the read scope"` tests fail along with the new `"marks which token is being used for the request"` test. Impact: the token-management list (the page this PR exists to improve) is completely unusable, and the new `is_current_token` field never renders. Smallest correction: ```elixir # lib/pleroma/web/o_auth/token_controller.ex |> render("index.json", %{tokens: oauth_tokens, current_token: current_token}) ``` ```elixir # lib/pleroma/web/o_auth/token_view.ex def render("index.json", %{tokens: tokens, current_token: current_token}) do tokens |> render_many(Pleroma.Web.OAuth.TokenView, "show.json", %{current_token: current_token}) |> Enum.filter(&Enum.any?/1) end ``` ### Checked and not raised - Nil-token path: `OAuthScopesPlug` halts with 403 before the action when the token assign is nil, so `current_token.id` cannot see `nil` here. - No other callers render `TokenView`, and the new test itself plus the changelog entry look fine once the plumbing is fixed. ### Merge readiness: 2/5 One P1 finding (caps the rating at 3/5): the PR's entire feature and the pre-existing list endpoint are broken, but the scope is narrow and the fix above is small. Re-run the token controller tests after fixing.
fix
All checks were successful
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.17 Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.19 Pipeline was successful
b748e8aea0
Author
Member

/oc review

/oc review
opencode-fix-bot left a comment

opencode-agent:job=172:generation=1

Verdict

No defects found in this pull request at the reviewed head. The P1 from the prior review (assign-key mismatch making GET /api/oauth_tokens return 500) is fixed: the controller, view, and render_many assigns are now consistent.

Verification

  • Inspected the exact base-to-head diff (4 files) plus lib/pleroma/web/plugs/o_auth_scopes_plug.ex, lib/pleroma/web/plugs/o_auth_plug.ex, and lib/pleroma/web/o_auth/token.ex.
  • lib/pleroma/web/o_auth/token_controller.ex:33 renders %{tokens:, current_token:}, matching lib/pleroma/web/o_auth/token_view.ex:8; the view forwards current_token through render_many, matching the "show.json" clause at lib/pleroma/web/o_auth/token_view.ex:16.
  • Ran mix test test/pleroma/web/o_auth/token_controller_test.exs against the exact head: 11 tests, 0 failures, including the new "marks which token is being used for the request" test.

Checked and not raised

  • Nil-token path: OAuthScopesPlug halts with 403 before the action when the token assign is nil, so current_token.id cannot see nil here.
  • No other callers render TokenView; the only producer of "show.json" assigns is the fixed "index.json" clause.
  • The new field exposes only a boolean is_current_token, not the token secret; the changelog entry is present.

Merge readiness: 5/5

Production-ready with no known findings.

opencode-agent:job=172:generation=1 ### Verdict No defects found in this pull request at the reviewed head. The P1 from the prior review (assign-key mismatch making `GET /api/oauth_tokens` return 500) is fixed: the controller, view, and `render_many` assigns are now consistent. ### Verification - Inspected the exact base-to-head diff (4 files) plus `lib/pleroma/web/plugs/o_auth_scopes_plug.ex`, `lib/pleroma/web/plugs/o_auth_plug.ex`, and `lib/pleroma/web/o_auth/token.ex`. - `lib/pleroma/web/o_auth/token_controller.ex:33` renders `%{tokens:, current_token:}`, matching `lib/pleroma/web/o_auth/token_view.ex:8`; the view forwards `current_token` through `render_many`, matching the `"show.json"` clause at `lib/pleroma/web/o_auth/token_view.ex:16`. - Ran `mix test test/pleroma/web/o_auth/token_controller_test.exs` against the exact head: 11 tests, 0 failures, including the new `"marks which token is being used for the request"` test. ### Checked and not raised - Nil-token path: `OAuthScopesPlug` halts with 403 before the action when the token assign is nil, so `current_token.id` cannot see `nil` here. - No other callers render `TokenView`; the only producer of `"show.json"` assigns is the fixed `"index.json"` clause. - The new field exposes only a boolean `is_current_token`, not the token secret; the changelog entry is present. ### Merge readiness: 5/5 Production-ready with no known findings.
hj merged commit ab8fae0b94 into develop 2026-11-05 16:38:21 +00:00
hj deleted branch oauth-mark 2026-11-05 16:38:21 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
pleroma/pleroma!8059
No description provided.