cloudwebrtc / go-protoo

A minimalist and extensible go signaling framework for WebRTC.
MIT License
23 stars 6 forks source link

Authenticating user request #9

Open tarrencev opened 4 years ago

tarrencev commented 4 years ago

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.

cloudwebrtc commented 4 years ago

@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
            }
}
tarrencev commented 4 years ago

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