Improve SWICG ActivityPub API Basic Profile conformance for C2S#3328
Merged
Conversation
Three additive, backward-compatible changes: - Return `activitypub_actor_id` alongside `me` in token and introspect responses so SWICG-aware clients can discover the authenticated actor under the spec name (existing IndieAuth `me` is preserved). - Normalize canonical SWICG scope identifiers in `Scope::validate()`: any `activitypub:read:*` collapses to the internal `read` scope and any `activitypub:write:*` collapses to `write`. Advertise both the internal scopes and the canonical aliases `activitypub:read:all` / `activitypub:write:all` in `scopes_supported`. - Emit `Retry-After: 60` on all OAuth 429 rate-limit responses (token, authorize, register) per RFC 6585 §4 so clients can back off. FEDERATION.md updated to list the Basic Profile under supported standards.
There was a problem hiding this comment.
Pull request overview
This PR improves the plugin’s OAuth-based Client-to-Server (C2S) behavior to better align with the SWICG ActivityPub API Basic Profile, while keeping changes additive/backward-compatible.
Changes:
- Add
activitypub_actor_idalongside IndieAuthmein token and introspection responses. - Accept canonical SWICG scope forms (
activitypub:read:*,activitypub:write:*) by normalizing them to the existing coarseread/writescopes, and advertise canonical aliases in OAuth metadata. - Include
Retry-After: 60on OAuth 429 rate-limit responses (token, authorize, client registration), and document this support inFEDERATION.md.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/phpunit/tests/includes/rest/oauth/class-test-token-controller.php | Asserts Retry-After on 429 and validates activitypub_actor_id parity with me in token/introspect responses. |
| tests/phpunit/tests/includes/rest/oauth/class-test-clients-controller.php | Validates Retry-After for registration 429s and that metadata advertises canonical scope aliases. |
| tests/phpunit/tests/includes/rest/oauth/class-test-authorization-controller.php | Validates Retry-After for authorize 429 responses. |
| tests/phpunit/tests/includes/oauth/class-test-scope.php | Adds coverage for canonical SWICG scope normalization, deduping, and supported-scope advertisement. |
| includes/rest/oauth/class-token-controller.php | Adds Retry-After header to token endpoint 429 error responses via token_error(). |
| includes/rest/oauth/class-clients-controller.php | Converts registration rate-limit WP_Error paths to 429 WP_REST_Response with Retry-After. |
| includes/rest/oauth/class-authorization-controller.php | Converts authorization rate-limit WP_Error paths to 429 WP_REST_Response with Retry-After. |
| includes/oauth/class-token.php | Adds activitypub_actor_id to token creation and introspection payloads (same value as me). |
| includes/oauth/class-server.php | Switches scopes_supported metadata to Scope::supported() to include canonical aliases. |
| includes/oauth/class-scope.php | Adds canonical alias support: normalize activitypub:read:*/activitypub:write:* to internal scopes and advertise aliases. |
| FEDERATION.md | Documents Basic Profile (partial) and Retry-After behavior for OAuth rate limiting. |
| .github/changelog/swicg-basic-profile-token-fields | Changelog entry for activitypub_actor_id addition. |
| .github/changelog/swicg-basic-profile-scope-aliases | Changelog entry for canonical scope alias support and advertisement. |
| .github/changelog/oauth-rate-limit-retry-after | Changelog entry for Retry-After on OAuth 429 responses. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #
Proposed changes:
Three additive, backward-compatible changes to bring the OAuth-based Client-to-Server surface closer to the SWICG ActivityPub API Basic Profile:
activitypub_actor_idalongside the existing IndieAuthmefield in token and introspect responses, so SWICG-aware clients can discover the authenticated actor under the spec property name. Same value for both fields; nothing is removed.Scope::validate()now collapses anyactivitypub:read:*to the internalreadscope and anyactivitypub:write:*towrite. Thescopes_supportedadvertised at/oauth/authorization-server-metadatanow includes the canonical aliasesactivitypub:read:allandactivitypub:write:allalongside the existingread/write/follow/push/profile. Enforcement stays coarse — there is no per-activity-type access control yet.Retry-After: 60on all OAuth 429 rate-limit responses (token, authorize, register) per RFC 6585 §4, so clients can back off cleanly. The token controller threads this through the existingtoken_error()helper; the authorize and register controllers convert theirWP_Errorpaths toWP_REST_Responsevia a smallrate_limit_response()helper kept private to each controller.FEDERATION.mdadds the Basic Profile to the list of supported standards and documents the C2S behavior in the OAuth section.Other information:
Testing instructions:
GET /wp-json/activitypub/1.0/oauth/authorization-server-metadataand confirmscopes_supportedcontains bothread/writeandactivitypub:read:all/activitypub:write:all.scope=activitypub:read:me:inboxand verify:meandactivitypub_actor_id, set to the same actor URI.scopein the response isread(collapsed from the canonical name)./oauth/token,/oauth/authorize, or/oauth/clientspast their per-minute caps and confirm the 429 response carriesRetry-After: 60.npm run env-test -- --group=oauthshould pass (179/179 locally).Changelog entry
Three entries already added under
.github/changelog/. No new entry needed via the workflow.Changelog Entry Details
Significance
Type
Message
C2S token responses now include
activitypub_actor_id; canonical SWICG scope names are accepted; OAuth rate-limit responses sendRetry-After.