feat(oauth2): allow a strategy to supply its own http_adapter - #1192
Open
pinetops wants to merge 3 commits into
Open
feat(oauth2): allow a strategy to supply its own http_adapter#1192pinetops wants to merge 3 commits into
pinetops wants to merge 3 commits into
Conversation
The plug unconditionally overwrote `config[:http_adapter]` with the
`:ash_authentication, :http_adapter` application setting (defaulting to
Finch), so a strategy could not use a bespoke HTTP adapter.
Add an `http_adapter` option to the `oauth2` DSL (a module or
`{module, opts}` tuple) and have the plug prefer it over the application
default. This lets a provider that needs bespoke transport handling — for
example an adapter that unwraps a non-standard response envelope before the
standard, spec-compliant OAuth2 parsing runs — plug in without
reimplementing the strategy.
Backward compatible: the option defaults to nil, so strategies that don't
set it fall back to the application setting exactly as before.
pinetops
marked this pull request as ready for review
July 24, 2026 19:19
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.
Problem
AshAuthentication.Strategy.OAuth2.Plugunconditionally overwritesconfig[:http_adapter]with the:ash_authentication, :http_adapterapplication setting (defaulting toFinch):So a strategy cannot use a custom
Assent.HTTPAdapter, even though Assent supports one via config. There is also no per-strategy way to configure it — only the global application setting.Motivation
Some providers return responses that aren't quite standard, and the clean way to handle that is a small custom
Assent.HTTPAdapterthat adjusts the response at the transport layer before Assent's spec-compliant OAuth2 parsing runs — keeping Assent itself unmodified and spec-pure.Concretely: Ed.link wraps its token and profile responses in a
{"$data": ...}envelope (which is not RFC 6749 §5.1-compliant). The correct fix is a transport adapter that unwraps it — but there was no way to hand that adapter to the strategy, because the plug clobbers it. (I initially proposed a hook in Assent for this — pow-auth/assent#205 — but that was reasonably rejected)Change
http_adapteroption to theoauth2DSL — a module or{module, opts}tuple.add_http_adapter/2preferstrategy.http_adapterover the application default.Compatibility
Backward compatible: the option defaults to
nil, so strategies that don't set it fall back to the application setting exactly as before. All OAuth2/OIDC-derived strategies inherit the option (regenerated cheat sheets included).Tests: a new plug test asserts a strategy's
http_adapterreaches the Assent config instead of the app default; the existing OAuth2 suite passes.