Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add authentication events #998

Merged
merged 15 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 159 additions & 0 deletions src/common/interfaces/event.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
} from '../../directory-sync/interfaces';
import { Connection, ConnectionResponse } from '../../sso/interfaces';
import {
AuthenticationEvent,
AuthenticationEventResponse,
Session,
SessionResponse,
User,
Expand All @@ -28,6 +30,139 @@ interface EventResponseBase {
created_at: string;
}

export interface AuthenticationEmailVerificationFailedEvent extends EventBase {
event: 'authentication.email_verification_failed';
data: AuthenticationEvent;
}

export interface AuthenticationEmailVerificationFailedEventResponse
extends EventResponseBase {
event: 'authentication.email_verification_failed';
data: AuthenticationEventResponse;
}

export interface AuthenticationEmailVerificationSucceededEvent
extends EventBase {
event: 'authentication.email_verification_succeeded';
data: AuthenticationEvent;
}

export interface AuthenticationEmailVerificationSucceededEventResponse
extends EventResponseBase {
event: 'authentication.email_verification_succeeded';
data: AuthenticationEventResponse;
}

export interface AuthenticationMagicAuthFailedEvent extends EventBase {
event: 'authentication.magic_auth_failed';
data: AuthenticationEvent;
}

export interface AuthenticationMagicAuthFailedEventResponse
extends EventResponseBase {
event: 'authentication.magic_auth_failed';
data: AuthenticationEventResponse;
}

export interface AuthenticationMagicAuthSucceededEvent extends EventBase {
event: 'authentication.magic_auth_succeeded';
data: AuthenticationEvent;
}

export interface AuthenticationMagicAuthSucceededEventResponse
extends EventResponseBase {
event: 'authentication.magic_auth_succeeded';
data: AuthenticationEventResponse;
}

export interface AuthenticationMfaFailedEvent extends EventBase {
event: 'authentication.mfa_failed';
data: AuthenticationEvent;
}

export interface AuthenticationMfaFailedEventResponse
extends EventResponseBase {
event: 'authentication.mfa_failed';
data: AuthenticationEventResponse;
}

export interface AuthenticationMfaSucceededEvent extends EventBase {
event: 'authentication.mfa_succeeded';
data: AuthenticationEvent;
}

export interface AuthenticationMfaSucceededEventResponse
extends EventResponseBase {
event: 'authentication.mfa_succeeded';
data: AuthenticationEventResponse;
}

export interface AuthenticationOAuthFailedEvent extends EventBase {
event: 'authentication.oauth_failed';
data: AuthenticationEvent;
}

export interface AuthenticationOAuthFailedEventResponse
extends EventResponseBase {
event: 'authentication.oauth_failed';
data: AuthenticationEventResponse;
}

export interface AuthenticationOAuthSucceededEvent extends EventBase {
event: 'authentication.oauth_succeeded';
data: AuthenticationEvent;
}

export interface AuthenticationOAuthSucceededEventResponse
extends EventResponseBase {
event: 'authentication.oauth_succeeded';
data: AuthenticationEventResponse;
}

export interface AuthenticationPasswordFailedEvent extends EventBase {
event: 'authentication.password_failed';
data: AuthenticationEvent;
}

export interface AuthenticationPasswordFailedEventResponse
extends EventResponseBase {
event: 'authentication.password_failed';
data: AuthenticationEventResponse;
}

export interface AuthenticationPasswordSucceededEvent extends EventBase {
event: 'authentication.password_succeeded';
data: AuthenticationEvent;
}

export interface AuthenticationPasswordSucceededEventResponse
extends EventResponseBase {
event: 'authentication.password_succeeded';
data: AuthenticationEventResponse;
}

export interface AuthenticationSSOFailedEvent extends EventBase {
event: 'authentication.sso_failed';
data: AuthenticationEvent;
}

export interface AuthenticationSSOFailedEventResponse
extends EventResponseBase {
event: 'authentication.sso_failed';
data: AuthenticationEventResponse;
}

export interface AuthenticationSSOSucceededEvent extends EventBase {
event: 'authentication.sso_succeeded';
data: AuthenticationEvent;
}

export interface AuthenticationSSOSucceededEventResponse
extends EventResponseBase {
event: 'authentication.sso_succeeded';
data: AuthenticationEventResponse;
}

export interface ConnectionActivatedEvent extends EventBase {
event: 'connection.activated';
data: Connection;
Expand Down Expand Up @@ -257,6 +392,18 @@ export interface SessionCreatedEventResponse extends EventResponseBase {
}

export type Event =
| AuthenticationEmailVerificationFailedEvent
| AuthenticationEmailVerificationSucceededEvent
| AuthenticationMfaFailedEvent
| AuthenticationMfaSucceededEvent
| AuthenticationOAuthFailedEvent
| AuthenticationOAuthSucceededEvent
| AuthenticationSSOFailedEvent
| AuthenticationSSOSucceededEvent
| AuthenticationPasswordFailedEvent
| AuthenticationPasswordSucceededEvent
| AuthenticationMagicAuthFailedEvent
| AuthenticationMagicAuthSucceededEvent
| ConnectionActivatedEvent
| ConnectionDeactivatedEvent
| ConnectionDeletedEvent
Expand All @@ -280,6 +427,18 @@ export type Event =
| SessionCreatedEvent;

export type EventResponse =
| AuthenticationEmailVerificationFailedEventResponse
| AuthenticationEmailVerificationSucceededEventResponse
| AuthenticationMagicAuthFailedEventResponse
| AuthenticationMagicAuthSucceededEventResponse
| AuthenticationMfaFailedEventResponse
| AuthenticationMfaSucceededEventResponse
| AuthenticationOAuthFailedEventResponse
| AuthenticationOAuthSucceededEventResponse
| AuthenticationPasswordFailedEventResponse
| AuthenticationPasswordSucceededEventResponse
| AuthenticationSSOFailedEventResponse
| AuthenticationSSOSucceededEventResponse
| ConnectionActivatedEventResponse
| ConnectionDeactivatedEventResponse
| ConnectionDeletedEventResponse
Expand Down
18 changes: 18 additions & 0 deletions src/common/serializers/event.serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '../../directory-sync/serializers';
import { deserializeConnection } from '../../sso/serializers';
import { deserializeUser } from '../../user-management/serializers';
import { deserializeAuthenticationEvent } from '../../user-management/serializers/authentication-event.serializer';
import { deserializeOrganizationMembership } from '../../user-management/serializers/organization-membership.serializer';
import { deserializeSession } from '../../user-management/serializers/session.serializer';
import { Event, EventBase, EventResponse } from '../interfaces';
Expand All @@ -19,6 +20,23 @@ export const deserializeEvent = (event: EventResponse): Event => {
};

switch (event.event) {
case 'authentication.email_verification_failed':
case 'authentication.email_verification_succeeded':
case 'authentication.magic_auth_failed':
case 'authentication.magic_auth_succeeded':
case 'authentication.mfa_failed':
case 'authentication.mfa_succeeded':
case 'authentication.oauth_failed':
case 'authentication.oauth_succeeded':
case 'authentication.password_failed':
case 'authentication.password_succeeded':
case 'authentication.sso_failed':
case 'authentication.sso_succeeded':
return {
...eventBase,
event: event.event,
data: deserializeAuthenticationEvent(event.data),
};
case 'connection.activated':
case 'connection.deactivated':
case 'connection.deleted':
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
interface AuthenticationEventError {
code: string;
message: string;
}

export type AuthenticationEventType =
| 'sso'
| 'password'
| 'oauth'
| 'mfa'
| 'magic_auth'
| 'email_verification';

export type AuthenticationEvent = {
type: AuthenticationEventType;
email?: string | null;
blairlunceford marked this conversation as resolved.
Show resolved Hide resolved
ipAddress: string | null;
userAgent: string | null;
userId: string | null;
error?: AuthenticationEventError;
};

export interface AuthenticationEventResponse {
type: AuthenticationEventType;
email?: string | null;
blairlunceford marked this conversation as resolved.
Show resolved Hide resolved
ip_address: string | null;
user_agent: string | null;
user_id: string | null;
error?: AuthenticationEventError;
}
1 change: 1 addition & 0 deletions src/user-management/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './authentication-event.interface';
export * from './authenticate-with-magic-auth-options.interface';
export * from './authenticate-with-password-options.interface';
export * from './authenticate-with-code-options.interface';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {
AuthenticationEvent,
AuthenticationEventResponse,
} from '../interfaces';

export const deserializeAuthenticationEvent = (
authenticationEvent: AuthenticationEventResponse,
): AuthenticationEvent => ({
type: authenticationEvent.type,
email: authenticationEvent.email,
ipAddress: authenticationEvent.ip_address,
userAgent: authenticationEvent.user_agent,
userId: authenticationEvent.user_id,
error: authenticationEvent.error,
});