Session authentication with Django channels

后端 未结 3 512
心在旅途
心在旅途 2021-02-01 06:35

Trying to get authentication working with Django channels with a very simple websockets app that echoes back whatever the user sends over with a prefix \"You said: \"

3条回答
  •  时光取名叫无心
    2021-02-01 07:08

    To answer your first question you need to use the:

    channel_session_user
    

    decorator in the receive and disconnect calls.

    channel_session_user_from_http
    

    calls the transfer_user session during the connect method to transfer the http session to the channel session. This way all future calls may access the channel session to retrieve user information.

    To your second question I believe what you are seeing is that default web socket library passes the browser cookies over the connection.

    Third, I think your setup will be working quite well once have changed the decorators.

提交回复
热议问题