1
1
# Django REST framework middlewares tutorial
2
2
3
3
- [ DRFAuthTokenMiddleware] ( #drfauthtokenmiddleware )
4
+ - [ QueryStringDRFAuthTokenMiddleware] ( #querystringdrfauthtokenmiddleware )
5
+ - [ DRFAuthTokenMiddlewareStack] ( #drfauthtokenmiddlewarestack )
4
6
- [ SimpleJWTAuthTokenMiddleware] ( #simplejwtauthtokenmiddleware )
7
+ - [ QueryStringSimpleJWTAuthTokenMiddleware] ( #queryStringsimplejwtauthtokenmiddleware )
8
+ - [ SimpleJWTAuthTokenMiddlewareStack] ( #simplejwtauthtokenmiddlewarestack )
5
9
6
10
7
11
## DRFAuthTokenMiddleware
@@ -100,25 +104,30 @@ application = ProtocolTypeRouter({
100
104
```
101
105
102
106
103
- ## SimpleJWTAuthTokenMiddleware
107
+ ## QueryStringDRFAuthTokenMiddleware
104
108
105
- > [ Simple JWT ] ( https://django-rest- framework-simplejwt.readthedocs.io/en/latest/index.html ) middleware
109
+ > Django REST framework auth token middleware with query string token
106
110
107
111
### Usage example
108
112
109
- > SimpleJWTAuthTokenMiddleware could be used directly or behind other auth middlewares or middleware stacks.
113
+ > Like DRFAuthTokenMiddleware QueryStringDRFAuthTokenMiddleware could be used directly or behind other auth middlewares or middleware stacks.
110
114
111
- Direct usage
115
+
116
+ ## DRFAuthTokenMiddlewareStack
117
+
118
+ > Combines DRFAuthTokenMiddleware and QueryStringDRFAuthTokenMiddleware
119
+
120
+ ### Usage example
112
121
113
122
``` python
114
123
from channels.routing import ProtocolTypeRouter, URLRouter
115
124
116
- from channels_auth_token_middlewares.middleware import SimpleJWTAuthTokenMiddleware
125
+ from channels_auth_token_middlewares.middleware import DRFAuthTokenMiddlewareStack
117
126
118
127
119
128
application = ProtocolTypeRouter({
120
129
121
- " websocket" : SimpleJWTAuthTokenMiddleware (
130
+ " websocket" : DRFAuthTokenMiddlewareStack (
122
131
URLRouter([
123
132
# app paths
124
133
]),
@@ -127,22 +136,44 @@ application = ProtocolTypeRouter({
127
136
})
128
137
```
129
138
130
- With AuthMiddlewareStack
139
+ Same example without stack
131
140
132
141
``` python
133
142
from channels.routing import ProtocolTypeRouter, URLRouter
134
- from channels.auth import AuthMiddlewareStack
135
143
136
- from channels_auth_token_middlewares.middleware import SimpleJWTAuthTokenMiddleware
144
+ from channels_auth_token_middlewares.middleware import DRFAuthTokenMiddleware, QueryStringDRFAuthTokenMiddleware
137
145
138
146
139
147
application = ProtocolTypeRouter({
140
148
141
- " websocket" : AuthMiddlewareStack(SimpleJWTAuthTokenMiddleware (
149
+ " websocket" : DRFAuthTokenMiddleware(QueryStringDRFAuthTokenMiddleware (
142
150
URLRouter([
143
151
# app paths
144
152
]),
145
153
)),
146
154
147
155
})
148
156
```
157
+
158
+
159
+ ## SimpleJWTAuthTokenMiddleware
160
+
161
+ > [ Simple JWT] ( https://django-rest-framework-simplejwt.readthedocs.io/en/latest/index.html ) middleware
162
+
163
+ ### Usage example
164
+
165
+ > Like DRFAuthTokenMiddleware SimpleJWTAuthTokenMiddleware could be used directly or behind other auth middlewares or middleware stacks.
166
+
167
+
168
+ ## QueryStringSimpleJWTAuthTokenMiddleware
169
+
170
+ > Simple JWT auth token middleware with query string token
171
+
172
+ ### Usage example
173
+
174
+ > Like DRFAuthTokenMiddleware QueryStringSimpleJWTAuthTokenMiddleware could be used directly or behind other auth middlewares or middleware stacks.
175
+
176
+
177
+ ## SimpleJWTAuthTokenMiddlewareStack
178
+
179
+ > Like DRFAuthTokenMiddlewareStack but combines SimpleJWTAuthTokenMiddleware and QueryStringSimpleJWTAuthTokenMiddleware
0 commit comments