AuthZen PDP client#4177
Merged
stevenvegt merged 5 commits intofeature/4144-mixed-scopesfrom Apr 24, 2026
Merged
Conversation
|
Coverage Impact ⬆️ Merging this pull request will increase total coverage on Modified Files with Diff Coverage (1)
🤖 Increase coverage with AI coding...🚦 See full report on Qlty Cloud » 🛟 Help
|
24 tasks
Implements the HTTP client for the AuthZen Access Evaluations API (POST /access/v1/evaluations). Request uses AuthZen batch format: shared subject/action/context with per-scope evaluations array. Returns scope→decision map. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Tests cover: partial denial, HTTP 500, PDP unreachable, context cancellation/timeout, evaluation count mismatch, malformed response. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Truncate PDP error body in error messages (prevent log injection) - Validate duplicate resource IDs before sending request - Add Accept: application/json header - Add package doc comment - Fix require.NoError inside httptest handler (capture request, assert outside) - Rename context cancellation test for accuracy - Add duplicate resource ID test - Response body limiting delegated to StrictHTTPClient (caller responsibility) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
7c44b2a to
4f08bcf
Compare
22 tasks
20 tasks
reinkrul
reviewed
Apr 17, 2026
- Adopt core.TestResponseCode for status validation; drops bespoke status check and error-body truncation (HttpError message omits the body, so no log-injection risk). - Wrap PDP error as "authzen: PDP call failed" to disambiguate from the AS server in mixed log output. - Replace duplicate-resource-ID comment with the actual rationale: AuthZen correlates request/response by index, so duplicate IDs would collapse map[string]bool decisions silently. - Clarify NewClient godoc: httpClient must enforce timeouts, TLS, and body size limits (use http/client.StrictHTTPClient in production). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
14 tasks
Base automatically changed from
4144-1-scope-parsing-and-config
to
feature/4144-mixed-scopes
April 24, 2026 12:33
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Parent PRD
#4144
Summary
New HTTP client for the AuthZen Access Evaluations batch API (
POST /access/v1/evaluations). Provides the types and the transport layer for dynamic scope policy evaluation. The server-side token flow in #4179 uses this client to evaluate requested scopes against an external PDP.What changed
New package
policy/authzen:types.go— AuthZen request/response types matching the AuthZen spec batch formatclient.go— Thin HTTP client with a singleEvaluatemethod returningmap[string]bool(scope → decision)client_test.go— Unit tests usinghttptest.NewServerBatch format: top-level
subject/action/contextare shared defaults, and anevaluationsarray contains per-scoperesourceoverrides. This avoids repeating shared fields for every scope.Error handling:
How to review
Start with
types.go— verify the AuthZen request/response shape against the spec (the batch format uses top-level defaults + per-evaluation overrides).Then
client.go— singleEvaluatemethod:Content-Type+AcceptheadersHTTPRequestDoer(StrictHTTPClient is used in wiring for response body limits / timeout)map[string]boolkeyed byResource.IDTests (
client_test.go) — 8 scenarios covering the full surface: success, partial denial, HTTP 500, unreachable endpoint, cancelled context, count mismatch, malformed response, duplicate resource IDs.Deviations from spec
Resource []Resource, implying a flat batch with multiple resources. During planning we verified this didn't match the AuthZen batch API. Corrected toEvaluations []Evaluationwith per-evaluation overrides, matching the spec's top-level-defaults-plus-overrides pattern.ExtractSubjectPropertieshelper. Moved to Server-side multi-scope flow & scope policy evaluation #4179 where the credential map's shape is concrete. This client is transport-only — it takes a pre-builtEvaluationsRequestfrom the caller.NewClientsignature simplified — notimeoutparameter. Timeout is the responsibility of the injectedHTTPRequestDoer(wired withStrictHTTPClientin Server-side multi-scope flow & scope policy evaluation #4179).Accept: application/jsonheader.subject.typein the PRD example was updated from"token_request"to"organization"(see PRD comment). The AuthZen client itself is agnostic — the caller sets the type.Dependencies
Depends on: #4176 (foundation PR, provides the base branch).
Review order: Review #4176 first for the foundation; this PR can then be reviewed independently as it's a self-contained new package with no cross-cutting changes.
Design context
Acceptance Criteria
Original implementation spec (used during AI-assisted development)
Parent PRD
#4144
Implementation Spec
Overview
New HTTP client for the AuthZen batch Access Evaluations API (
POST /access/v1/evaluations). This client is used by the server-side token flow (PR #4179) whenscope_policy: "dynamic"to evaluate requested scopes against an external PDP.Key files to create/modify
policy/authzen/client.go— New HTTP clientpolicy/authzen/types.go— Request/response typespolicy/authzen/client_test.go— Unit testsDesign decisions
evaluationsarray contains per-scope resource overrides. This avoids repeating the same subject/action/context for every scope.ExtractSubjectPropertieshelper depends on how the credential map from PEX evaluation maps to the organization bucket. This becomes clear in the server-side flow where the actual credential data is available. The AuthZen client takes a pre-builtEvaluationsRequest— it doesn't need to know about credentials.map[string]boolreturn type: Denial reasons from the AuthZen response are logged for debugging but not exposed in the return value. Rego-produced reasons are typically terse and few. A richer return type can be added later if operators need it.AuthZen request/response examples
Request (
POST /access/v1/evaluations):{ "subject": { "type": "token_request", "id": "did:web:hospital.example.com", "properties": { "organization": { "id": "did:web:hospital.example.com", "name": "Hospital B.V.", "ura": "12345678" } } }, "action": { "name": "request_scope" }, "context": { "policy": "urn:nuts:medication-overview" }, "evaluations": [ { "resource": { "type": "scope", "id": "urn:nuts:medication-overview" } }, { "resource": { "type": "scope", "id": "patient/Observation.read" } }, { "resource": { "type": "scope", "id": "launch/patient" } } ] }Response:
{ "evaluations": [ { "decision": true }, { "decision": true }, { "decision": false, "context": { "reason": "scope not permitted by policy" } } ] }Go types
Client implementation
The
Evaluatemethod:{endpoint}/access/v1/evaluations.map[string]boolfor easy lookup.Error handling
Testing
httptest.NewServerfor HTTP mockingAcceptance Criteria