There is native middleware in Channels. I have it documented with a brief example in the documentation, and I also mention some security measures.