@@ -196,6 +196,32 @@ The frontend is contained in the site folder.
196196
197197For buildingFrontend refer to [this document](docs/about/contributing/frontend.md )
198198
199+ ##RFC Compliance Development
200+
201+ ###Implementing Standard Protocols
202+
203+ When implementing standardprotocols (OAuth2,OpenID Connect , etc.):
204+
205+ 1 . **Fetch andAnalyze Official RFCs **:
206+ -Always read the actualRFC specifications before implementation
207+ -Use WebFetch tool to get currentRFC contentfor compliance verification
208+ -Document RFC requirements in code comments
209+
210+ 2 . **DefaultValues Matter **:
211+ -Pay close attention toRFC -specifieddefault values
212+ -Example :RFC 7591 specifies` client_secret_basic` asdefault , not` client_secret_post`
213+ -Ensure consistency between database migrations and application code
214+
215+ 3 . **SecurityRequirements **:
216+ -Follow RFC security considerations precisely
217+ -Example :RFC 7592 prohibits returning registration access tokens inGET responses
218+ -Implement propererror responses per protocol specifications
219+
220+ 4 . **ValidationCompliance **:
221+ -Implement comprehensive validation perRFC requirements
222+ -Support protocol-specificfeatures (e.g ., custom schemesfor nativeOAuth2 apps)
223+ -Test edge cases defined in specifications
224+
199225##Common Patterns
200226
201227###OAuth2 /AuthenticationWork
@@ -270,6 +296,32 @@ if errors.Is(err, errInvalidPKCE) {
270296-Test both positive and negative cases
271297-Use ` testutil.WaitLong` for timeouts in tests
272298
299+ ##Testing Best Practices
300+
301+ ###Avoiding Race Conditions
302+
303+ 1 . **UniqueTest Identifiers **:
304+ -Never use hardcoded names in concurrent tests
305+ -Use ` time.Now().UnixNano()` or similarfor unique identifiers
306+ -Example :` fmt.Sprintf("test-client-%s-%d", t.Name(), time.Now().UnixNano())`
307+
308+ 2 . **DatabaseConstraint Awareness **:
309+ -Understand unique constraints that can cause test conflicts
310+ -Generate unique valuesfor all constrained fields
311+ -Test name isolation prevents cross-test interference
312+
313+ ###RFC Protocol Testing
314+
315+ 1 . **ComplianceTest Coverage **:
316+ -Test allRFC -definederror codes and responses
317+ -Validate properHTTP status codesfor different scenarios
318+ -Test protocol-specific edgecases (URI formats, token formats, etc.)
319+
320+ 2 . **SecurityBoundary Testing **:
321+ -Test client isolation and privilege separation
322+ -Verify information disclosure protections
323+ -Test token security and proper invalidation
324+
273325##Code Navigation andInvestigation
274326
275327###Using Go LSP Tools (STRONGLYRECOMMENDED )
@@ -409,3 +461,67 @@ Always run the full test suite after OAuth2 changes:
4094617. **OAuth2 tests failing but scripts working** - Check in-memory database implementations in `dbmem.go`
4104628. **Resource indicator validation failing** - Ensure database stores and retrieves resource parameters correctly
4114639. **PKCE tests failing** - Verify both authorization code storage and token exchange handle PKCE fields
464+ 10. **Race conditions in tests** - Use unique identifiers instead of hardcoded names
465+ 11. **RFC compliance failures** - Verify against actual RFC specifications, not assumptions
466+ 12. **Authorization context errors in public endpoints** - Use `dbauthz.AsSystemRestricted(ctx)` pattern
467+ 13. **Default value mismatches** - Ensure database migrations match application code defaults
468+ 14. **Bearer token authentication issues** - Check token extraction precedence and format validation
469+ 15. **URI validation failures** - Support both standard schemes and custom schemes per protocol requirements
470+ 16. **Log message formatting errors** - Use lowercase, descriptive messages without special characters
471+
472+ ## Systematic Debugging Approach
473+
474+ ### Multi-Issue Problem Solving
475+
476+ When facing multiple failing tests or complex integration issues:
477+
478+ 1. **Identify Root Causes**:
479+ - Run failing tests individually to isolate issues
480+ - Use LSP tools to trace through call chains
481+ - Check both compilation and runtime errors
482+
483+ 2. **Fix in Logical Order**:
484+ - Address compilation issues first (imports, syntax)
485+ - Fix authorization and RBAC issues next
486+ - Resolve business logic and validation issues
487+ - Handle edge cases and race conditions last
488+
489+ 3. **Verification Strategy**:
490+ - Test each fix individually before moving to next issue
491+ - Use `make lint` and `make gen` after database changes
492+ - Verify RFC compliance with actual specifications
493+ - Run comprehensive test suites before considering complete
494+
495+ ### Authorization Context Patterns
496+
497+ Common patterns for different endpoint types:
498+
499+ ```go
500+ // Public endpoints needing system access (OAuth2 registration)
501+ app, err := api.Database.GetOAuth2ProviderAppByClientID(dbauthz.AsSystemRestricted(ctx), clientID)
502+
503+ // Authenticated endpoints with user context
504+ app, err := api.Database.GetOAuth2ProviderAppByClientID(ctx, clientID)
505+
506+ // System operations in middleware
507+ roles, err := db.GetAuthorizationUserRoles(dbauthz.AsSystemRestricted(ctx), userID)
508+ ```
509+
510+ ## Protocol Implementation Checklist
511+
512+ ### OAuth2/Authentication Protocol Implementation
513+
514+ Before completing OAuth2 or authentication feature work:
515+
516+ - [ ] Verify RFC compliance by reading actual specifications
517+ - [ ] Implement proper error response formats per protocol
518+ - [ ] Add comprehensive validation for all protocol fields
519+ - [ ] Test security boundaries and token handling
520+ - [ ] Update RBAC permissions for new resources
521+ - [ ] Add audit logging support if applicable
522+ - [ ] Create database migrations with proper defaults
523+ - [ ] Update in-memory database implementations
524+ - [ ] Add comprehensive test coverage including edge cases
525+ - [ ] Verify linting and formatting compliance
526+ - [ ] Test both positive and negative scenarios
527+ - [ ] Document protocol-specific patterns and requirements