Skip to content

Support to Dropwizard authentication #15

@danielborges93

Description

@danielborges93

Hi!

It is possible use the default io.dropwizard.auth with dropwizard-websockets?
In our project we are using OAuth authenticantion in resources.

I'm testing this class

@Timed(name = "timed")
@Metered(name = "metered")
@ExceptionMetered(name = "exception")
@ServerEndpoint("/socket")
@PermitAll
public class NotificationSocket {

    @OnOpen
    public void myOnOpen(final Session session) throws IOException {
        System.out.println("Principal: " + session.getUserPrincipal());
        session.getAsyncRemote().sendText("welcome");
    }

    @OnMessage
    public void myOnMsg(final Session session, String message) {
        session.getAsyncRemote().sendText(message);
    }

    @OnClose
    public void myOnClose(final Session session, CloseReason cr) {
    }

}

with this simple node script:

var WebSocket = require('ws')

const options = {
    headers: {
        'Authorization': 'Bearer token' // token is a system generated string
    }
}

const ws = new WebSocket('ws://localhost:58040/socket', options)
ws.on('message', function incoming(data) {
  console.log(data);
})

and the Principal always is null.

I want to associate each session ith the logged user.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions