quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.58k stars 2.63k forks source link

Header propagation does not work when RestClient is called from a @ServerEndpoint context #12125

Open philcolol opened 4 years ago

philcolol commented 4 years ago

We are using 'org.eclipse.microprofile.rest.client.propagateHeaders' property together with @RegisterClientHeaders annotation to propogate Authorization header to RestClients. It works when rest client called from Rest endpoints but fails with 401 when called from Webcosket endpoints. Is there some other configuration or well-known way to fix this?

To Reproduce Consider RestClient for some external service:

@Path("/externalService")
@RegisterRestClient
@RegisterClientHeaders
public interface DataService {

    @GET
    @Path("/method")
    @Produces("application/json")
    Set<String> getData();
}

A websocket endpoint that calls it:

@ServerEndpoint("/endpoint")         
@ApplicationScoped
public class WsEndpoint {

    @Inject
    ManagedExecutor executor;

    @Inject
    ThreadContext threadContext;

    @Inject
    @RestClient
    DataService dataService;

    @OnMessage
    public void onMessage(String message) {
        executor.submit(threadContext.contextualRunnable(() -> {
            session.getAsyncRemote().sendObject(dataService.getData()))));
        }
    }

}

And a request

curl \
    --include \
    --no-buffer \
    -H "Connection: Upgrade" \
    -H "Upgrade: websocket" \
    -H "Sec-WebSocket-Key: wPu/9zumjcR93EmDazjRFw==" \
    -H "Sec-WebSocket-Version: 13" \
    -H "Authorization: Bearer ey..." \
    http://127.0.0.1:8086/endpoint

Configuration

# Add your application.properties here, if applicable.
org.eclipse.microprofile.rest.client.propagateHeaders=Authorization

Environment (please complete the following information):

sberyozkin commented 4 years ago

@philcolol Is this header visible to the @ServerEndpoint ? I thought the HTTP headers were not available in the web socket channel, CC @stuartwdouglas

stuartwdouglas commented 4 years ago

This definitely won't work at the moment, but in theory it should be possible to make it work.

kenfinnigan commented 4 years ago

Agreed. The MP REST Client spec only details propagating headers from an incoming JAX-RS request.

dondragon2 commented 2 years ago

Has this been resolved? any workarounds?