go-protoo icon indicating copy to clipboard operation
go-protoo copied to clipboard

Authenticating user request

Open tarrencev opened this issue 5 years ago • 2 comments

Is it possible to return an authentication error from a consuming library? I am working on adding JWT auth to Ion and we need to be able to reject the socket connection (return 403). It seems since the response writer is not accessible this is not possible.

tarrencev avatar Jun 12 '20 14:06 tarrencev

@tarrencev Maybe we can add Authentication Handler at https://github.com/cloudwebrtc/go-protoo/blob/master/server/websocket_server.go#L48?

look like this:

cfg.WebSocketServerConfig{
    ....
   AuthenticationHandler: func(authinfo interface{}) (bool, error) {
          ok, err := jwt.AuthCheck(authinfo)
          return ok, err
  }
}
...
func (server *WebSocketServer) handleWebSocketRequest(writer http.ResponseWriter, request *http.Request) {
             authinfo := request.GetAuthInfo()
            if ok, err := server.cfg.AuthenticationHandler(authinfo); !ok {
                      // Authenticating failed!
                      writer.WriteCode(403)
                      return
            }
}

cloudwebrtc avatar Jun 13 '20 00:06 cloudwebrtc

I thought about this more and i think it makes more sense to just implement the server in Ion directly

tarrencev avatar Jun 14 '20 22:06 tarrencev