NaikSoftware / StompProtocolAndroid

STOMP protocol via WebSocket for Android
MIT License
597 stars 265 forks source link

Basic Auth #68

Open sayansiva opened 7 years ago

sayansiva commented 7 years ago

Is there any way I can provide my username to my spring backend ?

forresthopkinsa commented 7 years ago

What do you mean? Are you talking about authentication? Or just a plain HTTP header? You'll have to be more specific.

sayansiva commented 7 years ago

I am talking about the auth header. How to pass it ?

forresthopkinsa commented 7 years ago

There are two ways to pass auth headers, for different situations.

Firstly, to pass an auth header to the initial HTTP request, add it as a Map<String, String> to the Stomp.over method:

// login as 'user', with pass 'password'
Map<String, String> headerMap = Collections.singletonMap("Authorization", "Basic dXNlcjpwYXNzd29yZA==");
StompClient client = Stomp.over(... , ... , headerMap);
client.connect();

The second way is to pass auth headers with the STOMP Connect request, after the server's initial response and protocol upgrade. This request is not HTTP, it's STOMP. This is almost certainly not what you want.

List<StompHeader> headerList = new ArrayList<>();
StompHeader loginHeader = new StompHeader("login", "user");
StompHeader passHeader = new StompHeader("passcode", "password");
headerList.add(loginHeader);
headerList.add(passHeader);

StompClient client = Stomp.over(...);
client.connect(headerList);