Skip to content

fix: authorization scopes use REST resource shape#51

Merged
Subterrane merged 1 commit intomainfrom
fix/authorization-scopes-rest-shape
Apr 16, 2026
Merged

fix: authorization scopes use REST resource shape#51
Subterrane merged 1 commit intomainfrom
fix/authorization-scopes-rest-shape

Conversation

@Subterrane
Copy link
Copy Markdown
Contributor

Summary

  • add_authorization_scopes and remove_authorization_scopes were treating /api/2/api_authorizations/{id}/scopes as a bulk endpoint, sending {scopes: [...]}. core-api routes it as a standard nested REST resource (config/api2_routes.rb:65) — each POST creates one scope from {value, description}, each DELETE needs the numeric scope_id in the URL.
  • Same bug pattern that PR Fix add/remove_authorized_clients to use REST resource shape #48 fixed for /clients; /scopes was overlooked.
  • Both handlers now iterate and report per-item status, and inspect response.success from the API wrapper so the status field reflects reality (the client returns wrapped errors rather than throwing).

Fixes #49

Schema changes (breaking for anyone using the broken form)

  • add_authorization_scopes: scopes is now Array<{value, description?}> (was string[])
  • remove_authorization_scopes: replaces scopes: string[] with scope_ids: number[] (numeric IDs from list_authorization_scopes)

Returns a {results: [...]} envelope with per-item ok/error status, matching the pattern addAuthorizedClients/removeAuthorizedClients already use.

Test plan

Verified end-to-end against Chicken-Shadow:

  • Create a throwaway API authorization
  • add_authorization_scopes with two valid scopes + one whitespace value — two 201s, invalid item returns per-item error "Validation failed: Value may not have any whitespace characters"
  • list_authorization_scopes shows the two created with numeric IDs
  • remove_authorization_scopes with those IDs + one bogus ID — two oks, bogus gets per-item "The resource with the given id could not be found"
  • Final list is empty
  • Cleanup delete OK

The /scopes endpoint on api_authorizations is a standard nested REST
resource (config/api2_routes.rb:65), not a bulk endpoint. POST creates
one scope from {value, description}; DELETE requires the numeric
scope_id in the URL path.

- add_authorization_scopes now takes scopes: [{value, description?}]
  and iterates, reporting per-item status
- remove_authorization_scopes now takes scope_ids: [number] (from
  list_authorization_scopes) and iterates DELETE .../scopes/{scope_id}
- Both inspect response.success from the API wrapper so per-item
  status reflects actual outcomes (the client returns wrapped errors
  rather than throwing)

Same shape fix as PR #48 applied to the sibling /clients route.

Fixes #49
@Subterrane Subterrane merged commit 3ff5865 into main Apr 16, 2026
2 checks passed
@Subterrane Subterrane deleted the fix/authorization-scopes-rest-shape branch April 16, 2026 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add_authorization_scopes bug

1 participant