title: passing headers to Django channels using Javascript Websockets to authenticate user using Token
body: <p>i have no idea how to connect and authenticate django channels using token authentication because  javascript websockets doesnt support passing headers to the server </p>
  
  <pre><code>class TokenAuthMiddleware:
      """
      Token authorization middleware for Django Channels 2
      """
  
      def __init__(self, inner):
          self.inner = inner
  
      def __call__(self, scope):
          headers = dict(scope['headers'])
          if b'authorization' in headers:
              try:
                  token_name, token_key = headers[b'authorization'].decode().split()
                  if token_name == 'Token':
                      token = Token.objects.get(key=token_key)
                      scope['user'] = token.user
              except Token.DoesNotExist:
                  scope['user'] = AnonymousUser()
          return self.inner(scope)
  
  TokenAuthMiddlewareStack = lambda inner: TokenAuthMiddleware(AuthMiddlewareStack(inner))
  </code></pre>
  
  <p>I have found this answer regarding  authentication using token but the thing is I don't understand how to pass headers to the server</p>
  
  <pre><code>    token = Token.objects.get(key='175f76fd9b63a9477bf5f9a6f2e9a7f12ac62d65')
              if token.user:
                  scope['user'] = token.user
              else:
                  scope['user'] = AnonymousUser()
              return self.inner(scope)
  
  TokenAuthMiddlewareStack = lambda inner: TokenAuthMiddleware(AuthMiddlewareStack(inner))
  </code></pre>
  
  <p>when ever i manually authenticate users  the channels can recognize user and authenticate him</p>
  
  <p>i have tried </p>
  
  <pre><code>def get(request):
          for user in User.objects.all():
              token=Token.objects.get_or_create(user=request.user)
              if token.user:
                  print("ok")
              else:
                  print("not okay")
              print(token)
  </code></pre>
  
  <p>adding this function in the same class TokenAuthMiddleware
  i thought this would work but it's not working 
  so that i can use the token generated to authenticate users</p>
  
  <p>I just want to know  is there any way where i can authenticate users using token</p>