Preserve sso context in authentication event deserialisation#1487
Open
smorimoto wants to merge 2 commits intoworkos:mainfrom
Open
Preserve sso context in authentication event deserialisation#1487smorimoto wants to merge 2 commits intoworkos:mainfrom
smorimoto wants to merge 2 commits intoworkos:mainfrom
Conversation
Contributor
Greptile OverviewGreptile SummaryPreserves SSO context ( Changes:
Pattern consistency: Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant API as WorkOS Events API
participant Deserializer as deserializeEvent
participant AuthEvent as deserializeAuthenticationEvent
participant SSOHelper as deserializeAuthenticationEventSso
participant Client as SDK Consumer
API->>Deserializer: AuthenticationEventResponse (snake_case)
Deserializer->>AuthEvent: event.data (snake_case)
alt SSO authentication event with sso object
AuthEvent->>SSOHelper: authenticationEvent.sso
SSOHelper->>SSOHelper: Transform connection_id → connectionId
SSOHelper->>SSOHelper: Transform organization_id → organizationId
SSOHelper->>SSOHelper: Conditionally include session_id → sessionId
SSOHelper-->>AuthEvent: AuthenticationEventSso
AuthEvent->>AuthEvent: Conditionally spread sso object
else Non-SSO event (no sso object)
AuthEvent->>AuthEvent: Skip sso field entirely
end
AuthEvent-->>Deserializer: AuthenticationEvent (camelCase)
Deserializer-->>Client: Fully deserialized Event
Last reviewed commit: 84c4670 |
The Events API includes an sso object (with connection_id, organization_id, and optionally session_id) in authentication.sso_* event data, but the deserialiser was silently dropping it. Adds AuthenticationEventSso and AuthenticationEventSsoResponse interfaces, and a deserializeAuthenticationEventSso helper that follows the existing deserializeOauthTokens pattern for nested optional objects with snake_case conversion.
Switch from truthy checks (&&) to explicit !== undefined checks so that falsy values like empty strings are not incorrectly omitted.
a726c31 to
9541927
Compare
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.
Summary
AuthenticationEventSso/AuthenticationEventSsoResponseinterfaces for the nestedssoobject present in SSO authentication eventsdeserializeAuthenticationEventSsohelper to mapconnection_id,organization_id, andsession_iddeserializeAuthenticationEventto preserve thessocontextThe Events API documentation for authentication events includes an
ssoobject (withconnection_id,organization_id, and optionallysession_id) inauthentication.sso_*event data, but the deserialiser was silently dropping it.Design note
deserializeAuthenticationEventSsotakes a non-optionalAuthenticationEventSsoResponseargument and is called via the spread pattern at the call site:This ensures that when the
ssoobject is absent (non-SSO events), thessokey is not present in the deserialised output at all, rather than being set toundefined. The same approach is applied to the optionalsessionIdfield within thessoobject, which is only present on successful SSO authentications. This avoids polluting the output with keys that carry no value, keeping it consistent with what the Events API actually returns.This follows the existing
deserializeOauthTokenspattern used in the codebase for nested optional objects that require snake_case → camelCase conversion.Test plan
npx tsc --noEmit)npm test)