OpenFeed.ReqHttpAdapter (OpenFeed v0.1.0)

Copy Markdown View Source

An :oidcc_http_adapter backed by Req and Finch.

Why not the default

oidcc's default adapter is Erlang's httpc, which intermittently wedges against auth.openfeed.au: after a while every request fails with {:failed_connect, ..., :closed} and stays that way until the VM restarts. Finch's connection pooling does not exhibit that, and the rest of this library already talks to OpenFeed through Req, so there is one HTTP stack rather than two.

This is why openfeed requires oidcc 3.8 or later — 3.8.0 is the first release with pluggable HTTP adapters (erlef/oidcc#528).

Adapter config

Pass Req options through the adapter's config tuple. OpenFeed.Auth does this automatically from OpenFeed.Config's :req_options, which is how the test suite stubs the authorization server:

{OpenFeed.ReqHttpAdapter, %{req_options: [plug: {Req.Test, MyStub}]}}

Contract notes

Redirects are deliberately not followed, per the adapter contract, and responses are returned in the httpc shape oidcc expects: charlist header names and values, binary body. http_errors: :return matters — oidcc inspects 4xx bodies itself (a DPoP nonce challenge arrives as a 400), so raising on them would break the protocol.