This commit is contained in:
2025-12-04 15:49:57 +01:00
parent c698a0b893
commit 60a3c82cd9
26 changed files with 399 additions and 98 deletions

View File

@@ -0,0 +1,8 @@
import type { AuthProviderDTO } from './AuthProviderDTO';
export interface AuthCallbackCommandDTO {
provider: AuthProviderDTO;
code: string;
state: string;
returnTo?: string;
}

View File

@@ -0,0 +1 @@
export type AuthProviderDTO = 'IRACING_DEMO';

View File

@@ -0,0 +1,8 @@
import type { AuthenticatedUserDTO } from './AuthenticatedUserDTO';
export interface AuthSessionDTO {
user: AuthenticatedUserDTO;
issuedAt: number;
expiresAt: number;
token: string;
}

View File

@@ -0,0 +1,8 @@
export interface AuthenticatedUserDTO {
id: string;
displayName: string;
email?: string;
iracingCustomerId?: string;
primaryDriverId?: string;
avatarUrl?: string;
}

View File

@@ -0,0 +1,4 @@
export interface IracingAuthStateDTO {
state: string;
returnTo?: string;
}

View File

@@ -0,0 +1,6 @@
import type { AuthProviderDTO } from './AuthProviderDTO';
export interface StartAuthCommandDTO {
provider: AuthProviderDTO;
returnTo?: string;
}

View File

@@ -0,0 +1,8 @@
import type { AuthenticatedUserDTO } from '../dto/AuthenticatedUserDTO';
import type { AuthCallbackCommandDTO } from '../dto/AuthCallbackCommandDTO';
import type { StartAuthCommandDTO } from '../dto/StartAuthCommandDTO';
export interface IdentityProviderPort {
startAuth(command: StartAuthCommandDTO): Promise<{ redirectUrl: string; state: string }>;
completeAuth(command: AuthCallbackCommandDTO): Promise<AuthenticatedUserDTO>;
}

View File

@@ -0,0 +1,8 @@
import type { AuthenticatedUserDTO } from '../dto/AuthenticatedUserDTO';
import type { AuthSessionDTO } from '../dto/AuthSessionDTO';
export interface IdentitySessionPort {
getCurrentSession(): Promise<AuthSessionDTO | null>;
createSession(user: AuthenticatedUserDTO): Promise<AuthSessionDTO>;
clearSession(): Promise<void>;
}

View File

@@ -0,0 +1,14 @@
import type { AuthSessionDTO } from '../dto/AuthSessionDTO';
import type { IdentitySessionPort } from '../ports/IdentitySessionPort';
export class GetCurrentUserSessionUseCase {
private readonly sessionPort: IdentitySessionPort;
constructor(sessionPort: IdentitySessionPort) {
this.sessionPort = sessionPort;
}
async execute(): Promise<AuthSessionDTO | null> {
return this.sessionPort.getCurrentSession();
}
}

View File

@@ -0,0 +1,21 @@
import type { AuthCallbackCommandDTO } from '../dto/AuthCallbackCommandDTO';
import type { AuthSessionDTO } from '../dto/AuthSessionDTO';
import type { AuthenticatedUserDTO } from '../dto/AuthenticatedUserDTO';
import type { IdentityProviderPort } from '../ports/IdentityProviderPort';
import type { IdentitySessionPort } from '../ports/IdentitySessionPort';
export class HandleAuthCallbackUseCase {
private readonly provider: IdentityProviderPort;
private readonly sessionPort: IdentitySessionPort;
constructor(provider: IdentityProviderPort, sessionPort: IdentitySessionPort) {
this.provider = provider;
this.sessionPort = sessionPort;
}
async execute(command: AuthCallbackCommandDTO): Promise<AuthSessionDTO> {
const user: AuthenticatedUserDTO = await this.provider.completeAuth(command);
const session = await this.sessionPort.createSession(user);
return session;
}
}

View File

@@ -0,0 +1,13 @@
import type { IdentitySessionPort } from '../ports/IdentitySessionPort';
export class LogoutUseCase {
private readonly sessionPort: IdentitySessionPort;
constructor(sessionPort: IdentitySessionPort) {
this.sessionPort = sessionPort;
}
async execute(): Promise<void> {
await this.sessionPort.clearSession();
}
}

View File

@@ -0,0 +1,14 @@
import type { StartAuthCommandDTO } from '../dto/StartAuthCommandDTO';
import type { IdentityProviderPort } from '../ports/IdentityProviderPort';
export class StartAuthUseCase {
private readonly provider: IdentityProviderPort;
constructor(provider: IdentityProviderPort) {
this.provider = provider;
}
async execute(command: StartAuthCommandDTO): Promise<{ redirectUrl: string; state: string }> {
return this.provider.startAuth(command);
}
}