@rineex/auth-core 0.0.1 → 0.0.2

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.
@@ -0,0 +1,257 @@
1
+ # Auth Core — Domain Foundations (DDD + Hexagonal)
2
+
3
+ ## 1. Purpose
4
+
5
+ Design a **framework-agnostic, storage-agnostic authentication core** that:
6
+
7
+ - Works with **zero customization**
8
+ - Supports **incremental auth methods**
9
+ - Is suitable for **enterprise and simple products**
10
+ - Is extensible without modifying existing domain code
11
+ - Is independent of HTTP, DB, tokens, providers, or frameworks
12
+
13
+ This module defines **what authentication is**, not **how it is transported or
14
+ stored**.
15
+
16
+ ---
17
+
18
+ ## 2. Architectural Constraints (Hard Rules)
19
+
20
+ These rules must never be violated:
21
+
22
+ 1. Authentication is **not identity**
23
+ 2. Authentication methods are **plugins**
24
+ 3. Authentication flows are **data-driven**
25
+ 4. Infrastructure choices are **external**
26
+ 5. Domain owns **rules and invariants only**
27
+ 6. No provider, protocol, or framework knowledge in domain
28
+ 7. No auth method may require changing existing aggregates
29
+
30
+ If a new auth method breaks a rule → architecture is wrong.
31
+
32
+ ---
33
+
34
+ ## 3. Bounded Context
35
+
36
+ ### Authentication Context (this module)
37
+
38
+ Responsibilities:
39
+
40
+ - Verifying proof of access
41
+ - Orchestrating authentication flows
42
+ - Enforcing policies
43
+ - Producing authenticated sessions
44
+
45
+ Non-responsibilities:
46
+
47
+ - User profile management
48
+ - Authorization / permissions
49
+ - HTTP handling
50
+ - UI flows
51
+ - Token formats
52
+ - Database schemas
53
+
54
+ ---
55
+
56
+ ## 4. Ubiquitous Language (Canonical)
57
+
58
+ These terms have **single meanings** and must not be overloaded:
59
+
60
+ | Term | Meaning |
61
+ | ------------ | ----------------------------------------------- |
62
+ | Principal | Any actor that can authenticate |
63
+ | Credential | Authentication material owned by a principal |
64
+ | Auth Factor | Category of proof (knowledge, possession, etc.) |
65
+ | Auth Method | Concrete mechanism (password, otp, oauth, …) |
66
+ | Auth Attempt | One authentication execution |
67
+ | Auth Flow | Orchestration rules |
68
+ | Auth Policy | Constraints and conditions |
69
+ | Auth Proof | Verifiable evidence |
70
+ | Auth Result | Outcome of authentication |
71
+ | Session | Post-auth continuity |
72
+
73
+ ---
74
+
75
+ ## 5. Core Domain Aggregates
76
+
77
+ ### 5.1 Principal (Aggregate Root)
78
+
79
+ Represents **who or what** is authenticating.
80
+
81
+ **Key rules**
82
+
83
+ - Can exist without credentials
84
+ - Can represent humans, services, or devices
85
+ - Is auth-method agnostic
86
+
87
+ ---
88
+
89
+ ### 5.2 Credential (Entity)
90
+
91
+ Represents **what the principal owns** to authenticate.
92
+
93
+ **Key rules**
94
+
95
+ - Domain never stores secrets
96
+ - Lifecycle is domain-controlled
97
+ - Verification is delegated to infrastructure
98
+
99
+ ---
100
+
101
+ ### 5.3 AuthenticationAttempt (Aggregate Root)
102
+
103
+ Represents **one authentication process**.
104
+
105
+ **Why it exists**
106
+
107
+ - Prevents replay
108
+ - Supports MFA and step-up
109
+ - Enables audit and risk evaluation
110
+
111
+ ---
112
+
113
+ ### 5.4 AuthenticationSession (Aggregate Root)
114
+
115
+ Represents **authenticated continuity**.
116
+
117
+ **Key rules**
118
+
119
+ - Created only after successful authentication
120
+ - Stateless vs stateful is infrastructure choice
121
+ - Trust level is domain-owned
122
+
123
+ ---
124
+
125
+ ## 6. Value Objects (Core Concepts)
126
+
127
+ Value Objects define meaning, not storage:
128
+
129
+ - AuthMethodType
130
+ - AuthFactorType
131
+ - AuthProof
132
+ - TrustLevel
133
+ - RiskScore
134
+ - Challenge
135
+ - ContextSnapshot
136
+
137
+ Auth factors are **categories**, not implementations:
138
+
139
+ - Knowledge
140
+ - Possession
141
+ - Inherence
142
+ - Delegated
143
+
144
+ ---
145
+
146
+ ## 7. Authentication Methods (Extensibility Model)
147
+
148
+ Authentication methods are **not services** and **not branches**.
149
+
150
+ They are **capabilities described by data**.
151
+
152
+ An Auth Method defines:
153
+
154
+ - Its identifier
155
+ - Supported factors
156
+ - Required inputs
157
+ - Output proof type
158
+
159
+ The domain:
160
+
161
+ - Does not know _how_ a method works
162
+ - Does not know _who_ provides it
163
+ - Does not change when a method is added
164
+
165
+ ---
166
+
167
+ ## 8. Domain Services (Pure Logic)
168
+
169
+ ### Authentication Orchestrator
170
+
171
+ Coordinates attempts, proofs, and policies.
172
+
173
+ ### Policy Evaluator
174
+
175
+ Decides:
176
+
177
+ - Whether authentication is allowed
178
+ - Whether step-up is required
179
+ - Which flow applies
180
+
181
+ No domain service:
182
+
183
+ - Talks to HTTP
184
+ - Knows about tokens
185
+ - Knows about databases
186
+
187
+ ---
188
+
189
+ ## 9. Hexagonal Ports (Boundaries)
190
+
191
+ ### Persistence Ports
192
+
193
+ - PrincipalRepository
194
+ - CredentialRepository
195
+ - AuthenticationAttemptRepository
196
+ - AuthenticationSessionRepository
197
+
198
+ ### Capability Ports
199
+
200
+ - AuthProofVerifier
201
+ - ChallengeIssuer
202
+ - RiskEvaluator
203
+ - TokenIssuer
204
+
205
+ Infrastructure implements ports. Domain only defines **contracts**.
206
+
207
+ ---
208
+
209
+ ## 10. Phase 1 Auth Methods (Initial Scope)
210
+
211
+ Start small, cover most use cases:
212
+
213
+ 1. Password (compatibility)
214
+ 2. Passwordless (email magic)
215
+ 3. OTP (TOTP + Email)
216
+ 4. OAuth2 / OIDC
217
+ 5. Social Login
218
+ 6. API Tokens (M2M)
219
+
220
+ Everything else is additive.
221
+
222
+ ---
223
+
224
+ ## 11. Explicit Non-Goals (For Now)
225
+
226
+ These are **intentionally excluded**:
227
+
228
+ - HTTP redirects
229
+ - Cookies and headers
230
+ - JWT structure
231
+ - OAuth provider SDKs
232
+ - UI workflows
233
+ - Database schemas
234
+
235
+ They belong to adapters, not the core.
236
+
237
+ ---
238
+
239
+ ## 12. Extensibility Guarantees
240
+
241
+ Before adding any auth feature, verify:
242
+
243
+ - No existing aggregate changes
244
+ - No domain branching
245
+ - No infrastructure assumptions
246
+ - No HTTP dependency
247
+ - Enabled via configuration or policy
248
+
249
+ Failing any → redesign first.
250
+
251
+ ---
252
+
253
+ ## 13. Document Status
254
+
255
+ - This document is **authoritative**
256
+ - Any implementation must conform to it
257
+ - Changes require architectural justification
package/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # @rineex/auth-core
2
+
3
+ ## 0.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ [[`a347a2f`](https://github.com/rineex/core/commit/a347a2fbe9b1136c811f89a8ee4335bad13ca2ba)]:
9
+ - @rineex/ddd@1.5.2
10
+
11
+ ## 0.0.1
12
+
13
+ ### Patch Changes
14
+
15
+ - add initial documentation and modular structure for auth-core package
16
+ ([`bc6f1fc`](https://github.com/rineex/core/commit/bc6f1fce44cf9138ae417eb3463d1748b433d65c))