Base auth token middleware class.
Could be used behind other auth middlewares like channels.auth.AuthMiddleware.
Subclass of channels.auth.AuthMiddleware.
- inner - ASGI application (like channels.auth.AuthMiddleware inner argument)
- token_regex - token key validation regex, by default any string (r".*")
Returns user model instance or anonymous user instance.
- scope - channels.auth.AuthMiddleware scope
- Get token key string from the scope.
- Parse token key from token key string.
- Get user instance by token key.
Must be implemented by subclass to get token key string from the scope.
Implementation need to returns string to parse token key from or None.
- scope - channels.auth.AuthMiddleware scope
Parse token key from token key string by token key string regex.
By default returns full token key string content.
Returns token key as string or None.
- token_key_string - string to parse token key from
Returns regex to parse token key from token key string.
Token key need to be in first group.
Default is rf"({self.token_regex})"
Must be implemented by subclasses to get user instance by token key.
Implementation need to returns user instance or None.
- token_key - token key as string
Returns scope header value by name or None
- scope - channels.auth.AuthMiddleware scope
- header_name - header name as a string or bytes
Base middleware which parses auth token key from request header.
Subclass of BaseAuthTokenMiddleware.
- inner - ASGI application (like channels.auth.AuthMiddleware inner argument)
- token_regex - token key validation regex, by default any string (r".*")
- header_name - name of a header to get token key string from
- keyword - token key string keyword
Get token key string from header by header name.
Returns string to parse token key from or None.
- scope - channels.auth.AuthMiddleware scope
Returns regex to parse token key from token key string.
Default is rf"{self.keyword} ({self.token_regex})"
Must be implemented by subclasses to get user instance by token key.
Implementation need to returns user instance or None.
- token_key - token key as string
Base middleware which parses token key from request cookie.
Subclass of BaseAuthTokenMiddleware.
- inner - ASGI application (like channels.auth.AuthMiddleware inner argument)
- token_regex - token key validation regex, by default any string (r".*")
- cookie_name - name of a cookie to get token key string from
Get token key string from cookie by cookie name.
Returns string to parse token key from or None.
- scope - channels.auth.AuthMiddleware scope
Must be implemented by subclasses to get user instance by token key.
Implementation need to returns user instance or None.
- token_key - token key as string
Base middleware which parses token key from request query string.
Subclass of BaseAuthTokenMiddleware.
- inner - ASGI application (like channels.auth.AuthMiddleware inner argument)
- token_regex - token key validation regex, by default any string (r".*")
- query_param - name of a query param to get token key string from
Get token key string from query params by query param name.
Returns string to parse token key from or None.
- scope - channels.auth.AuthMiddleware scope
Must be implemented by subclasses to get user instance by token key.
Implementation need to returns user instance or None.
- token_key - token key as string