Skip to content

Commit 09a784c

Browse files
authored
Add auth failed events for SSO and OAuth (#248)
1 parent 3a3a3e2 commit 09a784c

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

src/main/kotlin/com/workos/webhooks/models/EventType.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ enum class EventType(
3131
*/
3232
AuthenticationMfaSucceeded("authentication.mfa_succeeded"),
3333

34+
/**
35+
* Triggers when a user fails to authenticate via OAuth.
36+
*/
37+
AuthenticationOauthFailed("authentication.oauth_failed"),
38+
3439
/**
3540
* Triggers when a user successfully authenticates via OAuth.
3641
*/
@@ -46,6 +51,11 @@ enum class EventType(
4651
*/
4752
AuthenticationPasswordSucceeded("authentication.password_succeeded"),
4853

54+
/**
55+
* Triggers when a user fails to authenticate with Single Sign-On.
56+
*/
57+
AuthenticationSsoFailed("authentication.sso_failed"),
58+
4959
/**
5060
* Triggers when a user successfully authenticates with Single Sign-On.
5161
*/

src/main/kotlin/com/workos/webhooks/models/WebhookJsonDeserializer.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ class WebhookJsonDeserializer : JsonDeserializer<WebhookEvent>() {
4444
EventType.AuthenticationMagicAuthFailed -> AuthenticationEvent(id, eventType, deserializeData(data, AuthenticationEventData::class.java), createdAt)
4545
EventType.AuthenticationMagicAuthSucceeded -> AuthenticationEvent(id, eventType, deserializeData(data, AuthenticationEventData::class.java), createdAt)
4646
EventType.AuthenticationMfaSucceeded -> AuthenticationEvent(id, eventType, deserializeData(data, AuthenticationEventData::class.java), createdAt)
47+
EventType.AuthenticationOauthFailed -> AuthenticationEvent(id, eventType, deserializeData(data, AuthenticationEventData::class.java), createdAt)
4748
EventType.AuthenticationOauthSucceeded -> AuthenticationEvent(id, eventType, deserializeData(data, AuthenticationEventData::class.java), createdAt)
4849
EventType.AuthenticationPasswordFailed -> AuthenticationEvent(id, eventType, deserializeData(data, AuthenticationEventData::class.java), createdAt)
4950
EventType.AuthenticationPasswordSucceeded -> AuthenticationEvent(id, eventType, deserializeData(data, AuthenticationEventData::class.java), createdAt)
51+
EventType.AuthenticationSsoFailed -> AuthenticationEvent(id, eventType, deserializeData(data, AuthenticationEventData::class.java), createdAt)
5052
EventType.AuthenticationSsoSucceeded -> AuthenticationEvent(id, eventType, deserializeData(data, AuthenticationEventData::class.java), createdAt)
5153
EventType.ConnectionActivated -> ConnectionActivatedEvent(id, eventType, deserializeData(data, Connection::class.java), createdAt)
5254
EventType.ConnectionDeactivated -> ConnectionDeactivatedEvent(id, eventType, deserializeData(data, Connection::class.java), createdAt)

src/test/kotlin/com/workos/test/webhooks/AuthenticationWebhookTests.kt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,24 @@ class AuthenticationWebhookTests : TestBase() {
125125
assertEquals((webhook as AuthenticationEvent).data.email, email)
126126
}
127127

128+
@Test
129+
fun constructAuthenticationOauthFailedEvent() {
130+
val workos = createWorkOSClient()
131+
val webhookData = generateAuthenticationFailedWebhookEvent(EventType.AuthenticationOauthFailed, "oauth")
132+
val testData = WebhooksApiTest.prepareTest(webhookData)
133+
134+
val webhook = workos.webhooks.constructEvent(
135+
webhookData,
136+
testData["signature"] as String,
137+
testData["secret"] as String
138+
)
139+
140+
assertTrue(webhook is AuthenticationEvent)
141+
assertEquals(webhook.id, webhookId)
142+
assertEquals((webhook as AuthenticationEvent).data.userId, userId)
143+
assertEquals((webhook as AuthenticationEvent).data.email, email)
144+
}
145+
128146
@Test
129147
fun constructAuthenticationOauthSucceededEvent() {
130148
val workos = createWorkOSClient()
@@ -179,6 +197,24 @@ class AuthenticationWebhookTests : TestBase() {
179197
assertEquals((webhook as AuthenticationEvent).data.email, email)
180198
}
181199

200+
@Test
201+
fun constructAuthenticationSsoFailedEvent() {
202+
val workos = createWorkOSClient()
203+
val webhookData = generateAuthenticationFailedWebhookEvent(EventType.AuthenticationSsoFailed, "sso")
204+
val testData = WebhooksApiTest.prepareTest(webhookData)
205+
206+
val webhook = workos.webhooks.constructEvent(
207+
webhookData,
208+
testData["signature"] as String,
209+
testData["secret"] as String
210+
)
211+
212+
assertTrue(webhook is AuthenticationEvent)
213+
assertEquals(webhook.id, webhookId)
214+
assertEquals((webhook as AuthenticationEvent).data.userId, userId)
215+
assertEquals((webhook as AuthenticationEvent).data.email, email)
216+
}
217+
182218
@Test
183219
fun constructAuthenticationSsoSucceededEvent() {
184220
val workos = createWorkOSClient()

0 commit comments

Comments
 (0)