1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
//! Framework-agnostic extension points for embedding the proxy.
//!
//! These traits let an embedding crate inject *stateless* service-specific logic
//! (a forward-auth/PDP decision, an OIDC discovery/JWKS/userinfo backing, extra
//! routes) without naming an HTTP framework in its own code or `Cargo.toml`.
//! All signatures use the foundational [`http`] crate (already in the tree via
//! both `axum` and `tonic`), [`bytes::Bytes`], and `serde_json::Value` (never an
//! `axum` type), so `cargo tree -i axum` in an embedder shows axum only under
//! `structured-proxy`.
//!
//! Stateful concerns (BFF sessions, OIDC `authorize`/`token`) are deliberately
//! absent: the default build is a stateless data plane (see the crate README
//! Non-goals). They are planned behind an opt-in `bff` feature.
use SocketAddr;
use Arc;
use async_trait;
use Bytes;
use ;
/// Borrowed view of an incoming request, passed to an [`AuthDecider`].
///
/// All fields borrow from the live request: building this is allocation-free, so
/// the per-request gate stays cheap. The body is intentionally absent: an auth
/// decision is taken from method, path, query, headers, and peer alone.
/// The outcome of an [`AuthDecider`] evaluation.
/// The per-request authorization gate.
///
/// Implemented by the embedder for its forward-auth / policy-decision logic
/// (e.g. JWT verification + a policy engine + header translation). Called inline
/// on every proxied request *and* by the `/verify` forward-auth endpoint: same
/// trait, two call sites.
/// Verifies a bearer token and yields its claims.
///
/// This is the seam the JWT middleware validates through. The built-in
/// implementation (`jsonwebtoken`, keys from `auth.jwt`) is what a plain
/// config-driven deployment gets; an embedder injects its own through
/// [`ProxyServer::with_token_verifier`](crate::ProxyServer::with_token_verifier)
/// when it needs a different signature backend — a validated / FIPS module, an
/// HSM, a shared verifier it already owns.
///
/// Injecting one is what makes the crypto backend a property of the *binary*
/// rather than of the dependency graph: Cargo unifies features across the whole
/// resolution, so two consumers of this crate that want different built-in
/// backends cannot coexist, while two consumers that inject their own verifiers
/// can. A build that injects one needs no crypto backend feature at all
/// (`default-features = false`), and then links no JWT crypto.
///
/// Everything around verification stays with the proxy: route policies
/// (`require_auth` / `required_roles`), the roles claim, and the claim→header
/// forwarding all operate on the returned claims.
/// A static JSON document served at a fixed path (an OIDC metadata document or a
/// JWKS document).
/// Backing for the *stateless* OIDC surface the proxy hosts.
///
/// The proxy owns the HTTP routes (discovery, JWKS, userinfo); the embedder
/// supplies their content from its own key/client metadata. No `authorize` /
/// `token` here: those are stateful and out of scope for the data plane.
/// Owned view of a request handed to an [`ExtraRouteHandler`].
///
/// Unlike [`RequestParts`], this owns its data (including the full body), since
/// an extra route may consume the body to produce a response.
/// Response produced by an [`ExtraRouteHandler`].
/// A stateless handler for an extra route registered via
/// [`ProxyServer::with_extra_routes`](crate::ProxyServer::with_extra_routes).
///
/// The framework-agnostic seam (request parts in, response parts out) the
/// embedder uses for service-specific endpoints without naming `axum`.
/// A single extra route: a method, a path, and the handler to run.