@breadstone/archipel-mcp 0.0.53 → 0.0.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data/guides/ai-image-generation.md +96 -0
- package/data/guides/ai-realtime-voice.md +69 -464
- package/data/guides/ai-text-generation.md +95 -622
- package/data/guides/index.md +3 -1
- package/data/guides/intelligence-prompts-warm-up.md +138 -0
- package/data/packages/platform-intelligence/api/Class.AnthropicIntelligenceProviderAdapter.md +78 -0
- package/data/packages/platform-intelligence/api/Class.DefaultIntelligencePromptPolicyAdapter.md +54 -0
- package/data/packages/platform-intelligence/api/Class.GatewayIntelligenceProviderAdapter.md +78 -0
- package/data/packages/platform-intelligence/api/Class.GoogleIntelligenceProviderAdapter.md +78 -0
- package/data/packages/platform-intelligence/api/Class.GrokIntelligenceProviderAdapter.md +78 -0
- package/data/packages/platform-intelligence/api/Class.IntelligenceAgent.md +95 -0
- package/data/packages/platform-intelligence/api/Class.IntelligenceAgentFactory.md +11 -23
- package/data/packages/platform-intelligence/api/Class.IntelligenceEmbeddingGenerator.md +25 -21
- package/data/packages/platform-intelligence/api/Class.IntelligenceHealthIndicator.md +11 -7
- package/data/packages/platform-intelligence/api/Class.IntelligenceLanguageGenerator.md +159 -0
- package/data/packages/platform-intelligence/api/Class.IntelligenceMediaGenerator.md +60 -38
- package/data/packages/platform-intelligence/api/Class.IntelligenceModule.md +2 -2
- package/data/packages/platform-intelligence/api/Class.IntelligencePromptExecutor.md +88 -0
- package/data/packages/platform-intelligence/api/Class.IntelligencePromptPolicyPort.md +48 -0
- package/data/packages/platform-intelligence/api/Class.IntelligenceProviderAssetUploader.md +21 -15
- package/data/packages/platform-intelligence/api/Class.IntelligenceProviderDiagnostics.md +55 -0
- package/data/packages/platform-intelligence/api/Class.IntelligenceProviderError.md +14 -4
- package/data/packages/platform-intelligence/api/Class.IntelligenceProviderRegistry.md +68 -0
- package/data/packages/platform-intelligence/api/Class.IntelligenceRealtimeError.md +9 -9
- package/data/packages/platform-intelligence/api/Class.IntelligenceRealtimeMeteringPort.md +2 -2
- package/data/packages/platform-intelligence/api/Class.IntelligenceRealtimeSessionFactory.md +12 -12
- package/data/packages/platform-intelligence/api/Class.IntelligenceRealtimeSessionPort.md +18 -18
- package/data/packages/platform-intelligence/api/Class.IntelligenceReranker.md +58 -0
- package/data/packages/platform-intelligence/api/Class.IntelligenceToolBase.md +14 -16
- package/data/packages/platform-intelligence/api/Class.IntelligenceToolRegistry.md +10 -14
- package/data/packages/platform-intelligence/api/Class.MiMoIntelligenceProviderAdapter.md +78 -0
- package/data/packages/platform-intelligence/api/Class.OpenAIIntelligenceProviderAdapter.md +102 -0
- package/data/packages/platform-intelligence/api/Function.createAnthropicAdvisor20260301Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicBash20241022Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicBash20250124Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicCodeExecution20250522Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicCodeExecution20250825Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicCodeExecution20260120Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicComputer20241022Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicComputer20250124Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicComputer20251124Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicMemory20250818Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicTextEditor20241022Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicTextEditor20250124Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicTextEditor20250429Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicTextEditor20250728Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicToolSearchBM2520251119Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicToolSearchRegex20251119Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicWebFetch20250910Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicWebFetch20260209Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicWebSearch20250305Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createAnthropicWebSearch20260209Tool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGoogleCodeExecutionTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGoogleEnterpriseWebSearchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGoogleFileSearchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGoogleGoogleMapsTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGoogleGoogleSearchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGoogleUrlContextTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGoogleVertexRagStoreTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGrokCodeExecutionTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGrokFileSearchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGrokMcpServerTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGrokViewImageTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGrokViewXVideoTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGrokWebSearchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createGrokXSearchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createIntelligenceJsonSchema.md +31 -0
- package/data/packages/platform-intelligence/api/Function.createIntelligenceTool.md +2 -2
- package/data/packages/platform-intelligence/api/Function.createMimoCustomTool.md +5 -5
- package/data/packages/platform-intelligence/api/Function.createOpenAIApplyPatchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAICodeInterpreterTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAICustomTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAIFileSearchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAIImageGenerationTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAILocalShellTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAIMcpTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAIShellTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAIToolSearchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAIWebSearchPreviewTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.createOpenAIWebSearchTool.md +1 -1
- package/data/packages/platform-intelligence/api/Function.defineIntelligenceTool.md +31 -0
- package/data/packages/platform-intelligence/api/Function.intelligencePrompt.md +31 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceAgentConfiguration.md +70 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceEmbeddingBatchOptions.md +124 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceEmbeddingBatchResult.md +70 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceEmbeddingOptions.md +114 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceEmbeddingResult.md +70 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceFileUploadOptions.md +102 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceFileUploadResult.md +60 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceGeneratedFile.md +40 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceGenerationStepStartEvent.md +50 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceImageGenerationOptions.md +170 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceImageGenerationResult.md +60 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceLanguageCompletion.md +141 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceLanguageGenerationOptions.md +234 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceLanguageStream.md +50 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceModelReference.md +34 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceModelRequestOptions.md +52 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceModelStatus.md +30 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceModuleOptions.md +43 -25
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceObjectStream.md +56 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligencePrompt.md +50 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligencePromptDefinition.md +145 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligencePromptEffectivePolicy.md +30 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligencePromptExecutionContext.md +20 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligencePromptExecutionPolicy.md +70 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligencePromptExecutionResult.md +127 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligencePromptInvocation.md +49 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligencePromptPolicyRequest.md +60 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligencePromptRenderContext.md +26 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceProviderAdapter.md +73 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceProviderConfiguration.md +10 -10
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceProviderLoadRequest.md +40 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceProviderProbeResult.md +70 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceRealtimeAudioFormat.md +3 -3
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceRealtimeCloseEvent.md +4 -4
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceRealtimeModuleOptions.md +9 -21
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceRealtimeSessionConfiguration.md +11 -11
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceRealtimeSessionOptions.md +11 -11
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceRealtimeToolDefinition.md +5 -5
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceRealtimeTranscriptionConfiguration.md +4 -4
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceRealtimeTurnDetectionConfiguration.md +5 -5
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceRealtimeUsage.md +10 -10
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceRequestOptions.md +98 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceRerankingOptions.md +140 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceRerankingResult.md +50 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceSkillUploadOptions.md +94 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceSkillUploadResult.md +80 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceSpeechGenerationOptions.md +164 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceSpeechGenerationResult.md +50 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceStreamingTranscriptionOptions.md +139 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceTool.md +7 -10
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceToolCall.md +40 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceToolDefinition.md +91 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceToolExecutionEndEvent.md +50 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceToolExecutionStartEvent.md +30 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceToolRegistry.md +4 -4
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceTranscriptionOptions.md +114 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceTranscriptionResult.md +84 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceTranscriptionStream.md +97 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceUsage.md +40 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceVideoGenerationOptions.md +229 -0
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceVideoGenerationResult.md +50 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IIntelligenceModelMessage.md +43 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IIntelligencePromptModelRequirement.md +25 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IIntelligenceSchema.md +70 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceCapability.md +14 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceDefaultModels.md +14 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceJsonValue.md +22 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligencePromptCapability.md +20 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligencePromptDefinitionConfiguration.md +29 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligencePromptGenerationOptions.md +16 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligencePromptLatency.md +14 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligencePromptMode.md +14 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligencePromptQuality.md +14 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligencePromptReasoning.md +14 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceProviderName.md +1 -1
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceProviderOptions.md +14 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceProviderProbeStatus.md +14 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceProviderToolOptions.md +17 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceRealtimeClientEvent.md +1 -1
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceRealtimeMetadataValue.md +1 -1
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceRealtimeMeteringEvent.md +1 -1
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceRealtimeServerEvent.md +1 -1
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceRealtimeStatus.md +1 -1
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceRequestTimeouts.md +14 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceToolChoice.md +21 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceToolOutput.md +22 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceToolSet.md +14 -0
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceTranscriptionStreamPart.md +46 -0
- package/data/packages/platform-intelligence/api/Variable.AI_GATEWAY_API_KEY.md +14 -0
- package/data/packages/platform-intelligence/api/Variable.AI_GATEWAY_BASE_URL.md +14 -0
- package/data/packages/platform-intelligence/api/Variable.AI_GATEWAY_CONFIG_ENTRIES.md +14 -0
- package/data/packages/platform-intelligence/api/Variable.INTELLIGENCE_API_KEY.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.INTELLIGENCE_BASE_URL.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.INTELLIGENCE_MAX_OUTPUT_TOKENS.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.INTELLIGENCE_MODEL.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.INTELLIGENCE_PROVIDER.md +2 -2
- package/data/packages/platform-intelligence/api/Variable.INTELLIGENCE_TEMPERATURE.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.INTELLIGENCE_TOP_P.md +1 -1
- package/data/packages/platform-intelligence/api/Variable.IntelligenceCapabilityNames.md +40 -0
- package/data/packages/platform-intelligence/api/Variable.IntelligenceProviderNames.md +2 -0
- package/data/packages/platform-intelligence/api/Variable.PLATFORM_INTELLIGENCE_CONFIG_ENTRIES.md +1 -1
- package/data/packages/platform-intelligence/api/index.md +98 -30
- package/package.json +1 -1
- package/data/packages/index.md +0 -8
- package/data/packages/platform-analytics/index.md +0 -209
- package/data/packages/platform-authentication/index.md +0 -725
- package/data/packages/platform-blob-storage/index.md +0 -416
- package/data/packages/platform-bootstrap/index.md +0 -162
- package/data/packages/platform-caching/index.md +0 -167
- package/data/packages/platform-configuration/index.md +0 -226
- package/data/packages/platform-core/index.md +0 -504
- package/data/packages/platform-cryptography/index.md +0 -142
- package/data/packages/platform-database/index.md +0 -337
- package/data/packages/platform-documents/index.md +0 -255
- package/data/packages/platform-esigning/index.md +0 -710
- package/data/packages/platform-feature-flags/index.md +0 -103
- package/data/packages/platform-health/index.md +0 -141
- package/data/packages/platform-intelligence/api/Class.IntelligenceStructuredGenerator.md +0 -70
- package/data/packages/platform-intelligence/api/Class.IntelligenceTelemetryRegistry.md +0 -44
- package/data/packages/platform-intelligence/api/Class.IntelligenceTextGenerator.md +0 -138
- package/data/packages/platform-intelligence/api/Function.createProviderOptions.md +0 -39
- package/data/packages/platform-intelligence/api/Function.loadAnthropicLanguageModel.md +0 -26
- package/data/packages/platform-intelligence/api/Function.loadGoogleLanguageModel.md +0 -26
- package/data/packages/platform-intelligence/api/Function.loadGoogleRealtimeModel.md +0 -25
- package/data/packages/platform-intelligence/api/Function.loadGrokLanguageModel.md +0 -26
- package/data/packages/platform-intelligence/api/Function.loadGrokRealtimeModel.md +0 -25
- package/data/packages/platform-intelligence/api/Function.loadMimoLanguageModel.md +0 -26
- package/data/packages/platform-intelligence/api/Function.loadOpenAILanguageModel.md +0 -26
- package/data/packages/platform-intelligence/api/Function.loadOpenAIRealtimeModel.md +0 -25
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceCompletionUsage.md +0 -46
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceTextCompletion.md +0 -168
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceTextGenerationOptions.md +0 -144
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceTextGenerator.md +0 -78
- package/data/packages/platform-intelligence/api/Interface.IIntelligenceTextStreamingOptions.md +0 -170
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceLanguageModelLoader.md +0 -24
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceLanguageModelLoaders.md +0 -14
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceRealtimeModelLoader.md +0 -25
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceRealtimeModelLoaders.md +0 -14
- package/data/packages/platform-intelligence/api/TypeAlias.IntelligenceTextStream.md +0 -14
- package/data/packages/platform-intelligence/index.md +0 -549
- package/data/packages/platform-logging/index.md +0 -150
- package/data/packages/platform-mailing/index.md +0 -470
- package/data/packages/platform-mapping/index.md +0 -123
- package/data/packages/platform-mcp/index.md +0 -335
- package/data/packages/platform-openapi/index.md +0 -207
- package/data/packages/platform-payments/index.md +0 -610
- package/data/packages/platform-queue/index.md +0 -192
- package/data/packages/platform-reporting/index.md +0 -233
- package/data/packages/platform-resources/index.md +0 -137
- package/data/packages/platform-telemetry/index.md +0 -262
|
@@ -1,725 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: platform-authentication
|
|
3
|
-
description: JWT, OAuth, MFA, sessions, and email verification with full Ports & Adapters decoupling.
|
|
4
|
-
order: 2
|
|
5
|
-
tags: [authentication, jwt, oauth, mfa, sessions, verification, ports-and-adapters, health]
|
|
6
|
-
package: '@breadstone/archipel-platform-authentication'
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
# platform-authentication
|
|
10
|
-
|
|
11
|
-
Full-featured authentication library supporting JWT tokens, OAuth social login (GitHub, Google, Microsoft, Apple), multi-factor authentication (TOTP, SMS, Email OTP, Push), session management, and email verification. Fully decoupled from user storage via 6 abstract ports.
|
|
12
|
-
|
|
13
|
-
**Package:** `@breadstone/archipel-platform-authentication`
|
|
14
|
-
|
|
15
|
-
<InstallTabs />
|
|
16
|
-
|
|
17
|
-
## Quick Start
|
|
18
|
-
|
|
19
|
-
```typescript
|
|
20
|
-
import { Module } from '@nestjs/common';
|
|
21
|
-
import { AuthModule } from '@breadstone/archipel-platform-authentication';
|
|
22
|
-
|
|
23
|
-
@Module({
|
|
24
|
-
imports: [
|
|
25
|
-
AuthModule.register({
|
|
26
|
-
authSubject: PrismaAuthSubjectAdapter,
|
|
27
|
-
mfaSubject: PrismaMfaSubjectAdapter,
|
|
28
|
-
sessionPersistence: PrismaSessionAdapter,
|
|
29
|
-
verificationSubject: PrismaVerificationAdapter,
|
|
30
|
-
socialAuth: PrismaSocialAuthAdapter, // optional — enables OAuth
|
|
31
|
-
tokenEnricher: AppTokenEnricherAdapter, // optional — enriches JWT claims
|
|
32
|
-
}),
|
|
33
|
-
],
|
|
34
|
-
})
|
|
35
|
-
export class AppModule {}
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
---
|
|
39
|
-
|
|
40
|
-
## Module Configuration
|
|
41
|
-
|
|
42
|
-
### IAuthModuleOptions
|
|
43
|
-
|
|
44
|
-
| Property | Type | Required | Description |
|
|
45
|
-
| --------------------- | ------------------------------- | -------- | ---------------------------------------------------------------------------------------------------- |
|
|
46
|
-
| `authSubject` | `Type<AuthSubjectPort>` | Yes | User lookup for JWT, Local, and Anonymous strategies |
|
|
47
|
-
| `mfaSubject` | `Type<MfaSubjectPort>` | Yes | MFA state persistence (secrets, channels, backup codes) |
|
|
48
|
-
| `sessionPersistence` | `Type<SessionPersistencePort>` | Yes | Session storage, querying, and invalidation |
|
|
49
|
-
| `verificationSubject` | `Type<VerificationSubjectPort>` | Yes | Email/PIN verification lifecycle |
|
|
50
|
-
| `challengeStore` | `Type<ChallengeStorePort>` | No | MFA challenge state persistence. Defaults to in-memory. Use Redis for multi-instance deployments. |
|
|
51
|
-
| `socialAuth` | `Type<SocialAuthPort>` | No | OAuth user creation/linking. When provided, GitHub/Google/Microsoft/Apple strategies are registered. |
|
|
52
|
-
| `tokenEnricher` | `Type<TokenEnricherPort>` | No | Custom JWT claim injection. When provided, additional claims are merged into access tokens. |
|
|
53
|
-
| `middleware` | `IAuthMiddlewareOptions` | No | Controls registration of `LastActiveMiddleware` and `LimitRequestSizeMiddleware`. Both enabled by default. |
|
|
54
|
-
|
|
55
|
-
### IAuthMiddlewareOptions
|
|
56
|
-
|
|
57
|
-
| Property | Type | Default | Description |
|
|
58
|
-
| ------------------ | ----------------- | ------------------ | ------------------------------------------------------------------------------------------------------------------- |
|
|
59
|
-
| `lastActive` | `boolean` | `true` | Enables `LastActiveMiddleware` on all routes. Set to `false` to disable last-active session tracking entirely. |
|
|
60
|
-
| `requestSizeLimit` | `false \| string` | `'auth/register'` | Path for the `LimitRequestSizeMiddleware` (POST only). Set to `false` to disable, or provide a custom path string. |
|
|
61
|
-
|
|
62
|
-
### Environment Variables
|
|
63
|
-
|
|
64
|
-
| Variable | Description | Required |
|
|
65
|
-
| ------------------------------ | ----------------------------------------------- | --------------------------- |
|
|
66
|
-
| `AUTH_JWT_SECRET` | JWT signing secret | Yes |
|
|
67
|
-
| `AUTH_JWT_EXPIRES_IN` | Token expiration (e.g. `'15m'`, `'1h'`, `'7d'`) | Yes |
|
|
68
|
-
| `AUTH_GITHUB_CLIENT_ID` | GitHub OAuth client ID | If using GitHub OAuth |
|
|
69
|
-
| `AUTH_GITHUB_CLIENT_SECRET` | GitHub OAuth client secret | If using GitHub OAuth |
|
|
70
|
-
| `AUTH_GOOGLE_CLIENT_ID` | Google OAuth client ID | If using Google OAuth |
|
|
71
|
-
| `AUTH_GOOGLE_CLIENT_SECRET` | Google OAuth client secret | If using Google OAuth |
|
|
72
|
-
| `AUTH_MICROSOFT_CLIENT_ID` | Microsoft OAuth client ID | If using Microsoft OAuth |
|
|
73
|
-
| `AUTH_MICROSOFT_CLIENT_SECRET` | Microsoft OAuth client secret | If using Microsoft OAuth |
|
|
74
|
-
| `AUTH_APPLE_CLIENT_ID` | Apple OAuth client ID | If using Apple OAuth |
|
|
75
|
-
| `AUTH_APPLE_TEAM_ID` | Apple team ID | If using Apple OAuth |
|
|
76
|
-
| `AUTH_APPLE_KEY_ID` | Apple key ID | If using Apple OAuth |
|
|
77
|
-
| `AUTH_APPLE_PRIVATE_KEY` | Apple private key (PEM) | If using Apple OAuth |
|
|
78
|
-
| `SEED_ANONYMOUS_USERNAME` | Username for anonymous/seed user | If using Anonymous strategy |
|
|
79
|
-
|
|
80
|
-
---
|
|
81
|
-
|
|
82
|
-
## Ports (Contracts)
|
|
83
|
-
|
|
84
|
-
### AuthSubjectPort
|
|
85
|
-
|
|
86
|
-
Resolves authentication subjects for JWT validation, local login, and anonymous access.
|
|
87
|
-
|
|
88
|
-
```typescript
|
|
89
|
-
abstract class AuthSubjectPort {
|
|
90
|
-
abstract findById(id: string): Promise<IAuthSubject | null>;
|
|
91
|
-
abstract findByLogin(login: string): Promise<IAuthSubject | null>;
|
|
92
|
-
abstract findAnonymous(userName: string): Promise<IAuthSubject | null>;
|
|
93
|
-
}
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
**IAuthSubject Interface:**
|
|
97
|
-
|
|
98
|
-
```typescript
|
|
99
|
-
interface IAuthSubject {
|
|
100
|
-
readonly id: string;
|
|
101
|
-
readonly userName: string | null;
|
|
102
|
-
readonly email: string | null;
|
|
103
|
-
readonly password: string | null;
|
|
104
|
-
readonly isVerified: boolean;
|
|
105
|
-
readonly isAnonymous: boolean;
|
|
106
|
-
readonly roles: ReadonlyArray<string>;
|
|
107
|
-
readonly mfaEnabled: boolean;
|
|
108
|
-
}
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
#### Real-World Adapter: Prisma
|
|
112
|
-
|
|
113
|
-
```typescript
|
|
114
|
-
@Injectable()
|
|
115
|
-
export class PrismaAuthSubjectAdapter extends AuthSubjectPort {
|
|
116
|
-
private readonly _prisma: PrismaService;
|
|
117
|
-
|
|
118
|
-
constructor(prisma: PrismaService) {
|
|
119
|
-
super();
|
|
120
|
-
this._prisma = prisma;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
public async findById(id: string): Promise<IAuthSubject | null> {
|
|
124
|
-
return this._prisma.user.findUnique({
|
|
125
|
-
where: { id },
|
|
126
|
-
select: {
|
|
127
|
-
id: true,
|
|
128
|
-
userName: true,
|
|
129
|
-
email: true,
|
|
130
|
-
password: true,
|
|
131
|
-
isVerified: true,
|
|
132
|
-
isAnonymous: true,
|
|
133
|
-
roles: true,
|
|
134
|
-
mfaEnabled: true,
|
|
135
|
-
},
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
public async findByLogin(login: string): Promise<IAuthSubject | null> {
|
|
140
|
-
return this._prisma.user.findFirst({
|
|
141
|
-
where: { OR: [{ userName: login }, { email: login }] },
|
|
142
|
-
select: {
|
|
143
|
-
id: true,
|
|
144
|
-
userName: true,
|
|
145
|
-
email: true,
|
|
146
|
-
password: true,
|
|
147
|
-
isVerified: true,
|
|
148
|
-
isAnonymous: true,
|
|
149
|
-
roles: true,
|
|
150
|
-
mfaEnabled: true,
|
|
151
|
-
},
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
public async findAnonymous(userName: string): Promise<IAuthSubject | null> {
|
|
156
|
-
return this._prisma.user.findFirst({
|
|
157
|
-
where: { userName, isAnonymous: true },
|
|
158
|
-
select: {
|
|
159
|
-
id: true,
|
|
160
|
-
userName: true,
|
|
161
|
-
email: true,
|
|
162
|
-
password: true,
|
|
163
|
-
isVerified: true,
|
|
164
|
-
isAnonymous: true,
|
|
165
|
-
roles: true,
|
|
166
|
-
mfaEnabled: true,
|
|
167
|
-
},
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
---
|
|
174
|
-
|
|
175
|
-
### SessionPersistencePort
|
|
176
|
-
|
|
177
|
-
Persists and queries user sessions.
|
|
178
|
-
|
|
179
|
-
```typescript
|
|
180
|
-
abstract class SessionPersistencePort {
|
|
181
|
-
abstract store(args: IStoreSessionArgs): Promise<void>;
|
|
182
|
-
abstract findByToken(token: string): Promise<ISessionRecord | null>;
|
|
183
|
-
abstract findAllByUserId(userId: string): Promise<ReadonlyArray<ISessionRecord>>;
|
|
184
|
-
abstract updateLastActive(token: string, date: Date): Promise<void>;
|
|
185
|
-
abstract invalidate(token: string): Promise<boolean>;
|
|
186
|
-
abstract invalidateById(id: string, userId: string): Promise<boolean>;
|
|
187
|
-
}
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
**IStoreSessionArgs:**
|
|
191
|
-
|
|
192
|
-
```typescript
|
|
193
|
-
interface IStoreSessionArgs {
|
|
194
|
-
readonly token: string;
|
|
195
|
-
readonly userId: string;
|
|
196
|
-
readonly ipAddress: string;
|
|
197
|
-
readonly deviceInfo?: IDeviceInfo;
|
|
198
|
-
readonly location?: string;
|
|
199
|
-
readonly clientName?: string;
|
|
200
|
-
}
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
**ISessionRecord:**
|
|
204
|
-
|
|
205
|
-
```typescript
|
|
206
|
-
interface ISessionRecord {
|
|
207
|
-
readonly id: string;
|
|
208
|
-
readonly token: string;
|
|
209
|
-
readonly userId: string;
|
|
210
|
-
readonly ipAddress: string;
|
|
211
|
-
readonly deviceType: string | null;
|
|
212
|
-
readonly deviceName: string | null;
|
|
213
|
-
readonly deviceOs: string | null;
|
|
214
|
-
readonly browser: string | null;
|
|
215
|
-
readonly location: string | null;
|
|
216
|
-
readonly clientName: string | null;
|
|
217
|
-
readonly lastActive: Date;
|
|
218
|
-
readonly createdAt: Date;
|
|
219
|
-
}
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
#### Real-World Adapter: Prisma
|
|
223
|
-
|
|
224
|
-
```typescript
|
|
225
|
-
@Injectable()
|
|
226
|
-
export class PrismaSessionAdapter extends SessionPersistencePort {
|
|
227
|
-
private readonly _prisma: PrismaService;
|
|
228
|
-
|
|
229
|
-
constructor(prisma: PrismaService) {
|
|
230
|
-
super();
|
|
231
|
-
this._prisma = prisma;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
public async store(args: IStoreSessionArgs): Promise<void> {
|
|
235
|
-
await this._prisma.session.upsert({
|
|
236
|
-
where: { token: args.token },
|
|
237
|
-
update: { lastActive: new Date() },
|
|
238
|
-
create: {
|
|
239
|
-
token: args.token,
|
|
240
|
-
userId: args.userId,
|
|
241
|
-
ipAddress: args.ipAddress,
|
|
242
|
-
deviceType: args.deviceInfo?.deviceType ?? null,
|
|
243
|
-
deviceName: args.deviceInfo?.deviceName ?? null,
|
|
244
|
-
deviceOs: args.deviceInfo?.os ?? null,
|
|
245
|
-
browser: args.deviceInfo?.browser ?? null,
|
|
246
|
-
location: args.location ?? null,
|
|
247
|
-
clientName: args.clientName ?? null,
|
|
248
|
-
lastActive: new Date(),
|
|
249
|
-
},
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
public async findByToken(token: string): Promise<ISessionRecord | null> {
|
|
254
|
-
return this._prisma.session.findUnique({ where: { token } });
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
public async findAllByUserId(userId: string): Promise<ReadonlyArray<ISessionRecord>> {
|
|
258
|
-
return this._prisma.session.findMany({
|
|
259
|
-
where: { userId },
|
|
260
|
-
orderBy: { lastActive: 'desc' },
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
public async updateLastActive(token: string, date: Date): Promise<void> {
|
|
265
|
-
await this._prisma.session.update({
|
|
266
|
-
where: { token },
|
|
267
|
-
data: { lastActive: date },
|
|
268
|
-
});
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
public async invalidate(token: string): Promise<boolean> {
|
|
272
|
-
const result = await this._prisma.session.deleteMany({ where: { token } });
|
|
273
|
-
return result.count > 0;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
public async invalidateById(id: string, userId: string): Promise<boolean> {
|
|
277
|
-
const result = await this._prisma.session.deleteMany({ where: { id, userId } });
|
|
278
|
-
return result.count > 0;
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
```
|
|
282
|
-
|
|
283
|
-
---
|
|
284
|
-
|
|
285
|
-
### MfaSubjectPort
|
|
286
|
-
|
|
287
|
-
MFA state persistence for managing secrets, channels, and backup codes.
|
|
288
|
-
|
|
289
|
-
```typescript
|
|
290
|
-
abstract class MfaSubjectPort {
|
|
291
|
-
abstract findById(id: string): Promise<IMfaSubject | null>;
|
|
292
|
-
abstract updateMfaState(id: string, update: IMfaSubjectUpdate): Promise<void>;
|
|
293
|
-
}
|
|
294
|
-
```
|
|
295
|
-
|
|
296
|
-
**IMfaSubject:**
|
|
297
|
-
|
|
298
|
-
```typescript
|
|
299
|
-
interface IMfaSubject {
|
|
300
|
-
readonly id: string;
|
|
301
|
-
readonly email: string | null;
|
|
302
|
-
readonly userName: string | null;
|
|
303
|
-
readonly mfaEnabled: boolean;
|
|
304
|
-
readonly mfaSecret: string | null;
|
|
305
|
-
readonly mfaBackupCodes: unknown;
|
|
306
|
-
readonly mfaPreferredMethod: string | null;
|
|
307
|
-
readonly mfaVerifiedAt: Date | null;
|
|
308
|
-
readonly mfaChannels: unknown;
|
|
309
|
-
readonly phoneNumber: string | null;
|
|
310
|
-
}
|
|
311
|
-
```
|
|
312
|
-
|
|
313
|
-
**IMfaSubjectUpdate:**
|
|
314
|
-
|
|
315
|
-
```typescript
|
|
316
|
-
interface IMfaSubjectUpdate {
|
|
317
|
-
readonly mfaChannels?: unknown;
|
|
318
|
-
readonly mfaEnabled?: boolean;
|
|
319
|
-
readonly mfaPreferredMethod?: string | null;
|
|
320
|
-
readonly mfaBackupCodes?: unknown;
|
|
321
|
-
readonly mfaVerifiedAt?: Date | null;
|
|
322
|
-
readonly mfaUpdatedAt?: Date | null;
|
|
323
|
-
readonly mfaSecret?: string | null;
|
|
324
|
-
readonly phoneNumber?: string | null;
|
|
325
|
-
}
|
|
326
|
-
```
|
|
327
|
-
|
|
328
|
-
---
|
|
329
|
-
|
|
330
|
-
### VerificationSubjectPort
|
|
331
|
-
|
|
332
|
-
Email and PIN verification lifecycle.
|
|
333
|
-
|
|
334
|
-
```typescript
|
|
335
|
-
abstract class VerificationSubjectPort {
|
|
336
|
-
abstract findByLogin(login: string): Promise<IVerifiableSubject | null>;
|
|
337
|
-
abstract findByVerificationToken(token: string): Promise<IVerifiableSubject | null>;
|
|
338
|
-
abstract setVerificationToken(id: string, token: string | null): Promise<void>;
|
|
339
|
-
abstract markVerified(id: string): Promise<void>;
|
|
340
|
-
}
|
|
341
|
-
```
|
|
342
|
-
|
|
343
|
-
**IVerifiableSubject:**
|
|
344
|
-
|
|
345
|
-
```typescript
|
|
346
|
-
interface IVerifiableSubject {
|
|
347
|
-
readonly id: string;
|
|
348
|
-
readonly email: string | null;
|
|
349
|
-
readonly userName: string | null;
|
|
350
|
-
readonly isVerified: boolean;
|
|
351
|
-
readonly verificationToken: string | null;
|
|
352
|
-
}
|
|
353
|
-
```
|
|
354
|
-
|
|
355
|
-
---
|
|
356
|
-
|
|
357
|
-
### ChallengeStorePort (Optional)
|
|
358
|
-
|
|
359
|
-
Persists MFA challenge state. The default implementation stores challenges in-memory (single instance only). For multi-instance deployments, provide a Redis-backed or database-backed implementation via `IAuthModuleOptions.challengeStore`.
|
|
360
|
-
|
|
361
|
-
```typescript
|
|
362
|
-
abstract class ChallengeStorePort {
|
|
363
|
-
abstract set(id: string, challenge: IMfaChallengeState): Promise<void>;
|
|
364
|
-
abstract get(id: string): Promise<IMfaChallengeState | undefined>;
|
|
365
|
-
abstract delete(id: string): Promise<void>;
|
|
366
|
-
}
|
|
367
|
-
```
|
|
368
|
-
|
|
369
|
-
**IMfaChallengeState:**
|
|
370
|
-
|
|
371
|
-
```typescript
|
|
372
|
-
interface IMfaChallengeState {
|
|
373
|
-
readonly userId: string;
|
|
374
|
-
readonly method: string;
|
|
375
|
-
readonly code?: string;
|
|
376
|
-
readonly issuedAt: Date;
|
|
377
|
-
readonly expiresAt: Date;
|
|
378
|
-
}
|
|
379
|
-
```
|
|
380
|
-
|
|
381
|
-
#### Redis Adapter Example
|
|
382
|
-
|
|
383
|
-
```typescript
|
|
384
|
-
@Injectable()
|
|
385
|
-
export class RedisChallengeStore extends ChallengeStorePort {
|
|
386
|
-
private readonly _redis: RedisClient;
|
|
387
|
-
|
|
388
|
-
constructor(redis: RedisClient) {
|
|
389
|
-
super();
|
|
390
|
-
this._redis = redis;
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
public async set(id: string, challenge: IMfaChallengeState): Promise<void> {
|
|
394
|
-
const ttl = Math.ceil((challenge.expiresAt.getTime() - Date.now()) / 1000);
|
|
395
|
-
await this._redis.set(`mfa:challenge:${id}`, JSON.stringify(challenge), 'EX', ttl);
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
public async get(id: string): Promise<IMfaChallengeState | undefined> {
|
|
399
|
-
const raw = await this._redis.get(`mfa:challenge:${id}`);
|
|
400
|
-
return raw ? JSON.parse(raw) : undefined;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
public async delete(id: string): Promise<void> {
|
|
404
|
-
await this._redis.del(`mfa:challenge:${id}`);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
```
|
|
408
|
-
|
|
409
|
-
---
|
|
410
|
-
|
|
411
|
-
### SocialAuthPort (Optional)
|
|
412
|
-
|
|
413
|
-
OAuth user creation and linking for social login providers.
|
|
414
|
-
|
|
415
|
-
```typescript
|
|
416
|
-
abstract class SocialAuthPort {
|
|
417
|
-
abstract findOrCreateByProfile(profile: ISocialProfile): Promise<IAuthSubject>;
|
|
418
|
-
}
|
|
419
|
-
```
|
|
420
|
-
|
|
421
|
-
**ISocialProfile:**
|
|
422
|
-
|
|
423
|
-
```typescript
|
|
424
|
-
interface ISocialProfile {
|
|
425
|
-
readonly provider: string; // e.g. 'github', 'google', 'microsoft', 'apple'
|
|
426
|
-
readonly userName: string | null;
|
|
427
|
-
readonly email: string | null;
|
|
428
|
-
readonly displayName: string | null;
|
|
429
|
-
}
|
|
430
|
-
```
|
|
431
|
-
|
|
432
|
-
#### Real-World Adapter
|
|
433
|
-
|
|
434
|
-
```typescript
|
|
435
|
-
@Injectable()
|
|
436
|
-
export class PrismaSocialAuthAdapter extends SocialAuthPort {
|
|
437
|
-
private readonly _prisma: PrismaService;
|
|
438
|
-
|
|
439
|
-
constructor(prisma: PrismaService) {
|
|
440
|
-
super();
|
|
441
|
-
this._prisma = prisma;
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
public async findOrCreateByProfile(profile: ISocialProfile): Promise<IAuthSubject> {
|
|
445
|
-
// Try to find existing user by email
|
|
446
|
-
let user = await this._prisma.user.findFirst({
|
|
447
|
-
where: { email: profile.email },
|
|
448
|
-
});
|
|
449
|
-
|
|
450
|
-
if (!user) {
|
|
451
|
-
// Create new user from social profile
|
|
452
|
-
user = await this._prisma.user.create({
|
|
453
|
-
data: {
|
|
454
|
-
email: profile.email,
|
|
455
|
-
userName: profile.userName ?? profile.displayName,
|
|
456
|
-
isVerified: true, // Social accounts are pre-verified
|
|
457
|
-
isAnonymous: false,
|
|
458
|
-
roles: ['user'],
|
|
459
|
-
authProviders: {
|
|
460
|
-
create: { provider: profile.provider },
|
|
461
|
-
},
|
|
462
|
-
},
|
|
463
|
-
});
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
return {
|
|
467
|
-
id: user.id,
|
|
468
|
-
userName: user.userName,
|
|
469
|
-
email: user.email,
|
|
470
|
-
password: null,
|
|
471
|
-
isVerified: user.isVerified,
|
|
472
|
-
isAnonymous: false,
|
|
473
|
-
roles: user.roles,
|
|
474
|
-
mfaEnabled: user.mfaEnabled ?? false,
|
|
475
|
-
};
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
```
|
|
479
|
-
|
|
480
|
-
---
|
|
481
|
-
|
|
482
|
-
### TokenEnricherPort (Optional)
|
|
483
|
-
|
|
484
|
-
Injects additional claims into JWT access tokens.
|
|
485
|
-
|
|
486
|
-
```typescript
|
|
487
|
-
abstract class TokenEnricherPort {
|
|
488
|
-
abstract enrichClaims(subject: IAuthSubject): Promise<Record<string, unknown>>;
|
|
489
|
-
}
|
|
490
|
-
```
|
|
491
|
-
|
|
492
|
-
#### Real-World Adapter
|
|
493
|
-
|
|
494
|
-
```typescript
|
|
495
|
-
@Injectable()
|
|
496
|
-
export class AppTokenEnricherAdapter extends TokenEnricherPort {
|
|
497
|
-
private readonly _prisma: PrismaService;
|
|
498
|
-
|
|
499
|
-
constructor(prisma: PrismaService) {
|
|
500
|
-
super();
|
|
501
|
-
this._prisma = prisma;
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
public async enrichClaims(subject: IAuthSubject): Promise<Record<string, unknown>> {
|
|
505
|
-
const subscription = await this._prisma.subscription.findFirst({
|
|
506
|
-
where: { userId: subject.id, status: 'active' },
|
|
507
|
-
select: { tier: true, expiresAt: true },
|
|
508
|
-
});
|
|
509
|
-
|
|
510
|
-
return {
|
|
511
|
-
tier: subscription?.tier ?? 'free',
|
|
512
|
-
subscriptionActive: subscription !== null,
|
|
513
|
-
};
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
```
|
|
517
|
-
|
|
518
|
-
---
|
|
519
|
-
|
|
520
|
-
## Services
|
|
521
|
-
|
|
522
|
-
### AuthTokenService
|
|
523
|
-
|
|
524
|
-
Creates JWT access tokens with base claims and optional enrichment.
|
|
525
|
-
|
|
526
|
-
```typescript
|
|
527
|
-
import { AuthTokenService } from '@breadstone/archipel-platform-authentication';
|
|
528
|
-
|
|
529
|
-
@Controller('auth')
|
|
530
|
-
export class AuthController {
|
|
531
|
-
constructor(private readonly _authToken: AuthTokenService) {}
|
|
532
|
-
|
|
533
|
-
@Post('login')
|
|
534
|
-
public async login(@Body() body: LoginDto): Promise<{ accessToken: string }> {
|
|
535
|
-
const subject: IAuthSubject = /* validated subject */;
|
|
536
|
-
const accessToken = await this._authToken.createAccessToken(subject);
|
|
537
|
-
return { accessToken };
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
```
|
|
541
|
-
|
|
542
|
-
The token payload includes `id`, `email`, `roles`, `iat`, `exp`, plus any claims from `TokenEnricherPort`.
|
|
543
|
-
|
|
544
|
-
### SessionService
|
|
545
|
-
|
|
546
|
-
Manages user sessions — creation, listing, activity tracking, and invalidation.
|
|
547
|
-
|
|
548
|
-
```typescript
|
|
549
|
-
import { SessionService } from '@breadstone/archipel-platform-authentication';
|
|
550
|
-
|
|
551
|
-
@Controller('sessions')
|
|
552
|
-
export class SessionController {
|
|
553
|
-
constructor(private readonly _sessions: SessionService) {}
|
|
554
|
-
|
|
555
|
-
@Get()
|
|
556
|
-
public async listSessions(@Req() req: Request): Promise<ISessionRecord[]> {
|
|
557
|
-
return this._sessions.listSessions(req.user.id);
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
@Delete(':id')
|
|
561
|
-
public async revokeSession(@Param('id') id: string, @Req() req: Request): Promise<boolean> {
|
|
562
|
-
return this._sessions.invalidateById(id, req.user.id);
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
```
|
|
566
|
-
|
|
567
|
-
### VerificationService
|
|
568
|
-
|
|
569
|
-
Handles email verification via token or PIN.
|
|
570
|
-
|
|
571
|
-
```typescript
|
|
572
|
-
import { VerificationService } from '@breadstone/archipel-platform-authentication';
|
|
573
|
-
|
|
574
|
-
// Token-based verification (email link)
|
|
575
|
-
const verified = await verificationService.verifyToken(token);
|
|
576
|
-
|
|
577
|
-
// PIN-based verification (6-digit code)
|
|
578
|
-
const verified = await verificationService.verifyPin(email, pin);
|
|
579
|
-
```
|
|
580
|
-
|
|
581
|
-
### MfaService
|
|
582
|
-
|
|
583
|
-
Orchestrates multi-factor authentication across all channels.
|
|
584
|
-
|
|
585
|
-
```typescript
|
|
586
|
-
import { MfaService } from '@breadstone/archipel-platform-authentication';
|
|
587
|
-
|
|
588
|
-
// Initiate MFA setup (returns QR code URI for TOTP)
|
|
589
|
-
const setup = await mfaService.initSetup(userId, 'totp');
|
|
590
|
-
|
|
591
|
-
// Verify and enable MFA
|
|
592
|
-
const confirmed = await mfaService.verifyAndEnable(userId, 'totp', code);
|
|
593
|
-
|
|
594
|
-
// Issue challenge during login
|
|
595
|
-
const challenge = await mfaService.issueChallenge(userId, 'totp');
|
|
596
|
-
|
|
597
|
-
// Verify challenge response
|
|
598
|
-
const valid = await mfaService.verifyChallenge(userId, 'totp', code);
|
|
599
|
-
```
|
|
600
|
-
|
|
601
|
-
### ChallengeService
|
|
602
|
-
|
|
603
|
-
Manages authentication challenge flows (e.g., during login when MFA is required).
|
|
604
|
-
|
|
605
|
-
---
|
|
606
|
-
|
|
607
|
-
## Guards
|
|
608
|
-
|
|
609
|
-
| Guard | Strategy | Description |
|
|
610
|
-
| -------------------- | --------- | ---------------------------------------------- |
|
|
611
|
-
| `JwtAuthGuard` | JWT | Validates Bearer token in Authorization header |
|
|
612
|
-
| `LocalAuthGuard` | Local | Username/password authentication |
|
|
613
|
-
| `AnonymousAuthGuard` | Anonymous | Seed/anonymous user access |
|
|
614
|
-
| `GithubAuthGuard` | GitHub | GitHub OAuth redirect |
|
|
615
|
-
| `RolesGuard` | — | RBAC guard checking `IAuthSubject.roles` |
|
|
616
|
-
|
|
617
|
-
### Using Guards
|
|
618
|
-
|
|
619
|
-
```typescript
|
|
620
|
-
import { JwtAuthGuard, RolesGuard } from '@breadstone/archipel-platform-authentication';
|
|
621
|
-
import { UseGuards } from '@nestjs/common';
|
|
622
|
-
|
|
623
|
-
@Controller('admin')
|
|
624
|
-
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
625
|
-
export class AdminController {
|
|
626
|
-
@Get('dashboard')
|
|
627
|
-
@Roles('admin')
|
|
628
|
-
public async getDashboard(): Promise<DashboardResponse> {
|
|
629
|
-
// Only accessible with valid JWT containing 'admin' role
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
```
|
|
633
|
-
|
|
634
|
-
---
|
|
635
|
-
|
|
636
|
-
## MFA Channels
|
|
637
|
-
|
|
638
|
-
The MFA system supports four channels, all orchestrated by `MfaService`:
|
|
639
|
-
|
|
640
|
-
| Channel | Class | Description |
|
|
641
|
-
| --------- | -------------------- | ---------------------------------------------------------- |
|
|
642
|
-
| TOTP | `TotpMfaChannel` | Time-based one-time password (Google Authenticator, Authy) |
|
|
643
|
-
| SMS | `SmsMfaChannel` | One-time code via SMS |
|
|
644
|
-
| Email OTP | `EmailOtpMfaChannel` | One-time code via email |
|
|
645
|
-
| Push | `PushMfaChannel` | Push notification approval |
|
|
646
|
-
|
|
647
|
-
All channels use the `MfaSubjectPort` for state persistence and `MfaEncryptionService` for secret encryption at rest.
|
|
648
|
-
|
|
649
|
-
---
|
|
650
|
-
|
|
651
|
-
## Authentication Strategies
|
|
652
|
-
|
|
653
|
-
| Strategy | Trigger | Port Used |
|
|
654
|
-
| ------------------- | --------------------------- | ---------------------------------------- |
|
|
655
|
-
| `JwtStrategy` | Bearer token in header | `AuthSubjectPort.findById()` |
|
|
656
|
-
| `LocalStrategy` | Username + password in body | `AuthSubjectPort.findByLogin()` |
|
|
657
|
-
| `AnonymousStrategy` | Anonymous access endpoint | `AuthSubjectPort.findAnonymous()` |
|
|
658
|
-
| `GithubStrategy` | GitHub OAuth callback | `SocialAuthPort.findOrCreateByProfile()` |
|
|
659
|
-
| `GoogleStrategy` | Google OAuth callback | `SocialAuthPort.findOrCreateByProfile()` |
|
|
660
|
-
| `MicrosoftStrategy` | Microsoft OAuth callback | `SocialAuthPort.findOrCreateByProfile()` |
|
|
661
|
-
| `AppleStrategy` | Apple OAuth callback | `SocialAuthPort.findOrCreateByProfile()` |
|
|
662
|
-
|
|
663
|
-
---
|
|
664
|
-
|
|
665
|
-
## JwtPayloadBase
|
|
666
|
-
|
|
667
|
-
Abstract base class for JWT payloads. Provides `toJSON()` / `fromJSON()` serialization and a `DefaultJwtPayload` subclass.
|
|
668
|
-
|
|
669
|
-
```typescript
|
|
670
|
-
import { JwtPayloadBase } from '@breadstone/archipel-platform-authentication';
|
|
671
|
-
|
|
672
|
-
// Decoding a JWT
|
|
673
|
-
const payload = JwtPayloadBase.fromJSON(decodedToken);
|
|
674
|
-
console.log(payload.id, payload.email, payload.roles);
|
|
675
|
-
```
|
|
676
|
-
|
|
677
|
-
---
|
|
678
|
-
|
|
679
|
-
## Health Check
|
|
680
|
-
|
|
681
|
-
The `AuthenticationHealthIndicator` reports the authentication subsystem as available. Import it from the `/health` subpath:
|
|
682
|
-
|
|
683
|
-
```typescript
|
|
684
|
-
import { AuthenticationHealthIndicator } from '@breadstone/archipel-platform-authentication/health';
|
|
685
|
-
import { HealthModule } from '@breadstone/archipel-platform-health';
|
|
686
|
-
|
|
687
|
-
@Module({
|
|
688
|
-
imports: [
|
|
689
|
-
AuthModule.register({ /* ... */ }),
|
|
690
|
-
HealthModule.withIndicators([AuthenticationHealthIndicator]),
|
|
691
|
-
],
|
|
692
|
-
})
|
|
693
|
-
export class AppModule {}
|
|
694
|
-
```
|
|
695
|
-
|
|
696
|
-
| Key | Check | Dependencies |
|
|
697
|
-
| --- | ----- | ------------ |
|
|
698
|
-
| `authentication` | Always reports `up` | None |
|
|
699
|
-
|
|
700
|
-
---
|
|
701
|
-
|
|
702
|
-
## Exports Summary
|
|
703
|
-
|
|
704
|
-
| Export | Type | Description |
|
|
705
|
-
| ------------------------- | ------------- | ----------------------------- |
|
|
706
|
-
| `AuthModule` | NestJS Module | Main module with `register()` |
|
|
707
|
-
| `AuthSubjectPort` | Port | User lookup |
|
|
708
|
-
| `MfaSubjectPort` | Port | MFA state |
|
|
709
|
-
| `SessionPersistencePort` | Port | Session storage |
|
|
710
|
-
| `VerificationSubjectPort` | Port | Verification lifecycle |
|
|
711
|
-
| `SocialAuthPort` | Port | OAuth user linking |
|
|
712
|
-
| `TokenEnricherPort` | Port | JWT claim enrichment |
|
|
713
|
-
| `ChallengeStorePort` | Port | MFA challenge persistence |
|
|
714
|
-
| `AuthTokenService` | Service | Token creation |
|
|
715
|
-
| `SessionService` | Service | Session management |
|
|
716
|
-
| `VerificationService` | Service | Email/PIN verification |
|
|
717
|
-
| `MfaService` | Service | MFA orchestration |
|
|
718
|
-
| `ChallengeService` | Service | Auth challenge flows |
|
|
719
|
-
| `JwtAuthGuard` | Guard | JWT validation |
|
|
720
|
-
| `LocalAuthGuard` | Guard | Local login |
|
|
721
|
-
| `AnonymousAuthGuard` | Guard | Anonymous access |
|
|
722
|
-
| `RolesGuard` | Guard | RBAC enforcement |
|
|
723
|
-
| `SessionMappingProfile` | Mapper | Session entity → response |
|
|
724
|
-
| `JwtPayloadBase` | Model | JWT payload abstraction |
|
|
725
|
-
| `AuthenticationHealthIndicator` | Health | Auth readiness check (`/health` subpath) |
|