gillesB
gillesB

Reputation: 1179

Digest authentication with Jetty Websocket client

I want to write a Java Websocket client which needs digest authentication to authenticate at a server.

I played around with the Jetty Websocket client example but I have no idea how to easily add the digest authentication. Furthermore I found no online resources which give a hint on how it could be done.

I also find it quite hard to find information online as most people use Jetty as server (obviously). For example this is not a duplicate: How to authenticate websocket client in jetty?

Therefore I am wondering if it is possible to use digest authentication with the Jetty Websocket client?

Upvotes: 0

Views: 1243

Answers (1)

ewnit
ewnit

Reputation: 21

you can try these two method:

  1. put your username and password in the websocket url.
    eg. ws://username:[email protected]/resturl

  2. generate Authorization and put this to the request header.

    String userpass = accessKey + ":" + secretKey;
    
    String authorization = "Basic " + new String(new Base64().encode(userpass.getBytes())).trim();
    
    ClientUpgradeRequest request = new ClientUpgradeRequest();
    
    request.setHeader("Authorization", authorization);
    

Upvotes: 2

Related Questions