Repository navigation
feat(actions): Add verify_action returning a typed action context - #776
Open
gjtorikian wants to merge 2 commits into
Open
gjtorikian wants to merge 2 commits into
gjtorikian wants to merge 2 commits into
Conversation
AuthKit Actions requests were only reachable through construct_action, which returns the verified payload as an untyped dict. Customers had to discover field names from example requests and index into the dict by hand, with no type checking or editor support. verify_action verifies the signature the same way and deserializes the payload into AuthenticationActionContext or UserRegistrationActionContext, discriminated on the object field. construct_action, verify_header, and sign_response keep their current signatures and behavior. The Action models are dedicated dataclasses rather than the generated REST models. The API sends a trimmed organization_membership (no roles) and a trimmed invitation (no token or accept_invitation_url), and the dashboard test request strips user and organization further. The generated models' strict from_dict would raise on every real request, so these models require only what the actions-types contract guarantees and treat the production extras as optional. AsyncActions is now a subclass of Actions instead of a duplicated copy.
Contributor
[Medium impact] The PR appears safe to merge; no actionable issues were found. SummaryAdds
No actionable issues were found. Review was based on source inspection; tests were not run. Reviews (1) · Last reviewed commit: "chore(actions): Describe the payload con..." · Reviewed by Greptile |
stanleyphu
approved these changes
Nov 10, 2026
This branch has not been deployed
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.
Description
Adds
client.actions.verify_action(), which verifies an AuthKit Actions request and deserializes it into a typedAuthenticationActionContextorUserRegistrationActionContext. This matches what the webhooks module already does withverify_event(). Until now Actions only offeredconstruct_action(), which returns an untyped dict, so customers had to discover field names from example requests and index into the dict by hand.Non-breaking.
construct_action(),verify_header(), andsign_response()keep their signatures and behavior.AsyncActionsis now a subclass ofActionsinstead of a duplicated copy.Why dedicated models instead of the generated REST models
The Actions payload is not part of the OpenAPI spec, so it cannot be generated. The shapes also differ from the REST models in ways that matter:
organization_membership(noroles) and a trimmedinvitation(notokenoraccept_invitation_url).userandorganizationarrive withoutexternal_id,metadata, and similar REST-only fields.The generated
User,Organization,OrganizationMembership, andInvitationmodels have a strictfrom_dictthat would raise on every one of those requests. The newAction*dataclasses require only what the contract guarantees and treat the production extras as optional. They reuse the generated enums andSlimRole, which already tolerate unknown values. The module header insrc/workos/actions.pyrecords this so nobody "fixes" it back to the REST models.Tests
tests/test_actions.pynow runs against realistic fixtures: a production authentication payload, a dashboard test-request payload, a user-registration payload with an invitation, and a minimal one without. It covers the sync and async client paths and rejects bad signatures, stale timestamps, non-object JSON, and unknownobjectvalues.ruff check/ruff format --checkpyright(strict,src+tests)tests/test_actions.py, Python 3.10Documentation
Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.
Not required: the change is additive and
construct_action()keeps working as documented. A follow-up docs PR can switch the Python snippet on the AuthKit Actions page toverify_action()once this ships. The README gains an "AuthKit Actions" section in this PR.