Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connectHeader is not passed to Spring server #23

Closed
arian-h opened this issue Nov 2, 2018 · 1 comment
Closed

connectHeader is not passed to Spring server #23

arian-h opened this issue Nov 2, 2018 · 1 comment

Comments

@arian-h
Copy link

arian-h commented Nov 2, 2018

Hello!

I have the following code, using the stomp js client:

this.client = new Client();
this.client.configure({
  brokerURL: 'ws://localhost:8443/api/wsocket',
  connectHeaders: {
    login: "user",
    passcode: "password"
  },
  onConnect: () => {
    console.log('onConnect');

    this.client.subscribe('/ws/quote', message => {
      console.log(message);
      debugger;
    });
  },
  // Helps during debugging, remove in production
  debug: (str) => {
    console.log(new Date(), str);
  }
});
this.client.activate();

I was following your stomp-spring-react project on github. The problem is that I don't receive the header on the server side. I have a JWT Authentication Filter, that gets hit, but I don't get the header payload when I want to access it via: request.getHeader. I checked all the header names using request.getHeaderNames but I don't see it there either. Is this a bug or am I missing something here?

@kum-deepak
Copy link
Member

I do not use Spring myself. Based on previous issues and Spring documentation I can suggest the following:

  • WebSocket internally connects using HTTP(S). request.getHeader returns headers from the HTTP connection. WebSocket protocol does not allow setting custom headers for the HTTP connection.
  • To get the headers from STOMP CONNECT frame you will need slightly different code. The best reference I have found is at: https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#websocket-stomp-authentication-token-based
  • This example demonstrates Token authentication, however you can authenticate using headers you are sending. Your header will be accessible through accessor which is MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class).

I hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants