I have two backends in two locations behind an Nginx frontend. Backend A implements authentication with OAuth. Backend B doesn't.
I think a lazy way of adding authentication for location B would be to send each request to backend A first. The flow I have in mind:
request for /b/kitten.png --> [ nginx ]
[ nginx ] --> request for /index.html --> [backend A]
if A responds 200:
[ nginx ] --> request for /kitten.png --> [backend B]
otherwise return what A returned (redirect to OAuth)
Is this possible in Nginx? If not, maybe in OpenResty/HAProxy/Traefik?