【发布时间】:2020-06-01 15:45:32
【问题描述】:
我正在使用 Django REST 框架 TokenAuthentication。
对于一些 URL,我不得不在 URL 路径中包含令牌:
https://example.com/api/<auth_token>/something
所以 urlpatterns 是:
urlpatterns = [
path('api/<auth_token>/something', views.SomeView.as_view()),
]
而观点是:
class SomeView(APIView):
authentication_classes = (TokenAuthentication)
permission_classes = (IsAuthenticated, )
def get(self, request, auth_token):
...
但是TokenAuthentication 在这里不起作用,因为令牌在 URL 路径中,而不是在标头中。如果可能的话,我想扩展 TokenAuthentication 以处理 URL 内令牌。
【问题讨论】:
-
@RyanWilson 用一些代码澄清了这个问题。
-
谢谢你,安德烈。
标签: django django-rest-framework