From 31c51f734d8d7c899047d65cdedcb3c843bc3b88 Mon Sep 17 00:00:00 2001 From: Ryan Cooke Date: Mon, 13 Jan 2025 10:47:20 -0800 Subject: [PATCH] Add device fingerprint to action context payloads (#1199) When Radar is enabled, the device fingerprint captured by Radar is forwarded in action request payloads. This PR adds the attribute to action interfaces. ## Description ## Documentation Does this require changes to the WorkOS Docs? E.g. the [API Reference](https://workos.com/docs/reference) or code snippets need updates. ``` [ ] Yes ``` If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required. --- src/actions/actions.spec.ts | 2 ++ src/actions/fixtures/authentication-action-context.json | 3 ++- src/actions/fixtures/user-registration-action-context.json | 5 +++-- src/actions/interfaces/action.interface.ts | 4 ++++ src/actions/serializers/action.serializer.ts | 2 ++ 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/actions/actions.spec.ts b/src/actions/actions.spec.ts index bd2d956b1..0b73f880b 100644 --- a/src/actions/actions.spec.ts +++ b/src/actions/actions.spec.ts @@ -129,6 +129,7 @@ describe('Actions', () => { }, ipAddress: '50.141.123.10', userAgent: 'Mozilla/5.0', + deviceFingerprint: 'notafingerprint', issuer: 'test', object: 'authentication_action_context', organization: { @@ -175,6 +176,7 @@ describe('Actions', () => { }, ipAddress: '50.141.123.10', userAgent: 'Mozilla/5.0', + deviceFingerprint: 'notafingerprint', invitation: expect.objectContaining({ object: 'invitation', id: '01JBVZWH8HJ855YZ5BWHG1WNZN', diff --git a/src/actions/fixtures/authentication-action-context.json b/src/actions/fixtures/authentication-action-context.json index a7e28ccab..314395aeb 100644 --- a/src/actions/fixtures/authentication-action-context.json +++ b/src/actions/fixtures/authentication-action-context.json @@ -13,6 +13,7 @@ }, "ip_address": "50.141.123.10", "user_agent": "Mozilla/5.0", + "device_fingerprint": "notafingerprint", "issuer": "test", "object": "authentication_action_context", "organization": { @@ -37,4 +38,4 @@ "created_at": "2024-10-22T17:12:50.746Z", "updated_at": "2024-10-22T17:12:50.746Z" } -} \ No newline at end of file +} diff --git a/src/actions/fixtures/user-registration-action-context.json b/src/actions/fixtures/user-registration-action-context.json index 65ea30a4f..3969b1e97 100644 --- a/src/actions/fixtures/user-registration-action-context.json +++ b/src/actions/fixtures/user-registration-action-context.json @@ -8,6 +8,7 @@ }, "ip_address": "50.141.123.10", "user_agent": "Mozilla/5.0", + "device_fingerprint": "notafingerprint", "object": "user_registration_action_context", "invitation": { "object": "invitation", @@ -20,5 +21,5 @@ "revoked_at": null, "organization_id": "01JBW46BTKAA98WZN8826XQ2YP", "inviter_user_id": "01JBVZWAEPWAE3YYKBVT0AF81F" - } -} \ No newline at end of file + } +} diff --git a/src/actions/interfaces/action.interface.ts b/src/actions/interfaces/action.interface.ts index 419a01393..b8db8df2c 100644 --- a/src/actions/interfaces/action.interface.ts +++ b/src/actions/interfaces/action.interface.ts @@ -19,6 +19,7 @@ interface AuthenticationActionContext { organizationMembership?: OrganizationMembership; ipAddress?: string; userAgent?: string; + deviceFingerprint?: string; issuer?: string; } @@ -36,6 +37,7 @@ interface UserRegistrationActionContext { invitation?: Invitation; ipAddress?: string; userAgent?: string; + deviceFingerprint?: string; } export type ActionContext = @@ -50,6 +52,7 @@ interface AuthenticationActionPayload { organization_membership?: OrganizationMembershipResponse; ip_address?: string; user_agent?: string; + device_fingerprint?: string; issuer?: string; } @@ -67,6 +70,7 @@ export interface UserRegistrationActionPayload { invitation?: InvitationResponse; ip_address?: string; user_agent?: string; + device_fingerprint?: string; } export type ActionPayload = diff --git a/src/actions/serializers/action.serializer.ts b/src/actions/serializers/action.serializer.ts index 6c36dcb1a..330da06b1 100644 --- a/src/actions/serializers/action.serializer.ts +++ b/src/actions/serializers/action.serializer.ts @@ -35,6 +35,7 @@ export const deserializeAction = ( ipAddress: actionPayload.ip_address, userAgent: actionPayload.user_agent, + deviceFingerprint: actionPayload.device_fingerprint, }; case 'authentication_action_context': return { @@ -51,6 +52,7 @@ export const deserializeAction = ( : undefined, ipAddress: actionPayload.ip_address, userAgent: actionPayload.user_agent, + deviceFingerprint: actionPayload.device_fingerprint, issuer: actionPayload.issuer, }; }