feat: Update Actor Account Portability OAuth field plus codebase and tests refactor #231
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.
This PR makes a review and update of the existing Actor Account Portability OAuth field and introduces a complete production-ready implementation of OAuth discovery and conditional migration properties specifications, with comprehensive test suite refactoring and configuration improvements.
Closes #230
Most of the infrastructure about this feature was already implemented but there were mismatches with LOLA specification that needed to be addressed.
accountPortabilityOAuth field
We were adding
accountPortabilityOauthfield only when authenticated with portability scope:But the
accountPortabilityOauthfield must ALWAYS be present for OAuth endpoint discovery, regardless of authentication status.Per LOLA spec: ActivityPub servers supporting this specification MUST provide the URL for their portability authorization endpoint in Actor objects, using the "accountPortabilityOauth" field.
Example of an Actor object with public response from LOLA specification:
{ "@context": [ "https://www.w3.org/ns/activitystreams", "https://purl.archive.org/socialweb/blocked" ], "id": "https://oakfrost.example.com/brock", "type": "Person", "name": "Brock Oakfrost", "accountPortabilityOauth": "https://example.com/oauth2/porting-access-endpoint", "inbox": "https://oakfrost.example.com/brock/inbox" }Enhanced actor response with authorization token
Example of an Actor object response with account migration authorization token included in request
{ "@context": [ "https://www.w3.org/ns/activitystreams", "https://purl.archive.org/socialweb/blocked", # New - From LOLA examples "https://swicg.github.io/activitypub-data-portability/lola" # New - Custom Field to reference LOLA ], "id": "<https://oakfrost.example.com/brock>", "type": "Person", "name": "Brock Oakfrost", "accountPortabilityOauth": "<https://example.com/oauth2/porting-access-endpoint>", "inbox": "<https://oakfrost.example.com/brock/inbox>", "outbox": "<https://oakfrost.example.com/brock/outbox>", "following": "<https://oakfrost.example.com/brock/following>", "followers": "<https://oakfrost.example.com/brock/followers>", "liked": "<https://oakfrost.example.com/brock/liked>", "blocked": "<https://oakfrost.example.com/brock/blocked>", "migration": { "outbox": "<https://oakfrost.example.com/brock/migration/outbox>", "content": "<https://oakfrost.example.com/brock/migration/content>", "following": "<https://oakfrost.example.com/brock/migration/following>", "blocked": "<https://oakfrost.example.com/brock/migration/blocked>" } }blockedto context from LOLA specificationmigration URLs
In the LOLA spec example:
The URLs include
/migration/in the path but our implementation doesn't have thoseBut according to LOLA specification:
LOLA spec allows flexibility here so I decided to keep the original implementation (without adding
/migration) for now. It may be changed if necessary in the future.OAuth Endpoint URL Builder
In
def build_oauth_endpoint_url()in oauth_utils.py I updated the fallback for possible edge cases and add BASE_URL to the settings files since the fallback tohttps://example.comcould possible cause issues and didn't look good.Current Behavior
Result:
http://localhost:8000/oauth/authorize/https://activitypub-testbed-stg-run-737003321709.us-central1.run.apphttps://ap-testbed.dtinit.org/oauth/authorize/This works as expected. The URL is dynamically built from the actual request.
Adding BASE_URL to 6 settings files just allow us a proper fallback.
Actor JSON-LD Builder
Testing
test_lola_actor.pythat contains just the LOLA compliance tests related to this implementation (following pythonic approach) and frees up the size of thetest_api.pyfile.Test implementation via Curl commands
1. Public Request (No Authentication)
This verifies that
accountPortabilityOauthis always present but NO migration data:Should be present:
accountPortabilityOauthShould not be present:
migration,following,followers,liked,blocked,outbox2. Authenticated Request (With Portability Token)
To test this we need a valid OAuth token with
activitypub_account_portabilityscope.Expected:
accountPortabilityOauth,migrationobject, all collections (following, followers, liked, blocked, outbox)3. Wrong Scope Test (Should Return Public Response)
Expected: Same as public request (no migration data)