Behind Fly, NGINX, a CDN, or any reverse proxy, the request the application
sees is not the request the client sent: the scheme is often plain HTTP after
TLS termination, and the Host header may be an internal name. OAuth and OIDC
URL correctness depends on the canonical, client-visible host and scheme,
not on whatever reached the application socket.
Why this matters
The issuer (
iss) is minted into every token and published in the discovery documents (RFC 8414 §2). It MUST be the canonicalhttpsURL clients use. Deriving it from a live request behind a proxy can leak an internal host or anhttpscheme.The DPoP
htu(RFC 9449 §4.3) is the URL the client signed. If the server computeshtufrom a proxied request it may not match what the client signed, and valid proofs are rejected.Redirect URIs are exact-matched (RFC 6749 §3.1.2.3). A host/scheme mismatch breaks the match.
Configure the canonical identity, not the request
:issuer- set this to the fixed canonicalhttpsissuer URL. The library derives the discovery issuer and the advertised endpoint URLs from it (via the:oauth_path_prefix/ per-endpoint path resolvers), so it never needs to reconstruct the host from a request. This is stable behind any TLS terminator.:trusted_proxies- the list of trusted proxy CIDRs/IPs that controls whetherX-Forwarded-*headers are honored. Default[](no forwarded trust): nothing is taken from aForwarded/X-Forwarded-*header unless the immediate peer is in this list. Set it to your proxy's address range so forwarded scheme/host are trusted only from your proxy and never from an arbitrary client.:require_https- keep thistrue(the default) in production so the endpoints enforce HTTPS.:resource_origin- the fixed canonicalhttpsorigin of the protected resources, such as"https://api.example.com". The DPoPhtuat every protected resource (AttestoPhoenix.Plug.Authenticate, the bundled UserInfo and credential endpoints) is this origin followed by the request path, so neither the proxy hop nor a client-chosenHostaffects it. It is independent of:issuer, because the resource server and the authorization server may live on different origins.:htu-(conn -> canonical_url_string). When neither the configured URLs nor:resource_origindescribe the topology (protected resources on several origins, a path-rewriting proxy), override exactly how the DPoPhtuis computed. Return the canonical URL the client would have signed, built from configured origins rather than request headers. Mutually exclusive with:resource_origin.
Where the DPoP htu comes from
- Token, PAR, and device authorization endpoints: their configured public
URL (derived from
:issuer), or an exact:mtls_endpoint_aliasesentry when the request arrives on that alias. - Protected resources:
:htuif set; otherwise:resource_originfollowed by the request path; otherwise the URL rebuilt from the request through:trusted_proxies. The last form takes its host from the requestHostheader (or the forwarded host from a trusted proxy), so a server that answers more than oneHostaccepts a DPoP-bound token with a proof made for another server.
Checklist
- [ ]
:issueris the fixed canonicalhttpsURL (no internal host). - [ ]
:resource_originis the canonicalhttpsorigin of your protectedresources if they accept DPoP-bound tokens. - [ ]
:trusted_proxieslists your proxy's address range, nothing wider. - [ ]
:require_httpsistrue. - [ ] Advertised endpoint paths match the mount via
:oauth_path_prefix(seethe consumer migration guide). - [ ] If proofs are rejected behind the proxy and
:resource_origindoes notdescribe the topology, set `:htu` to return the canonical signed URL.