TastyPie - Override_urls忽略身份验证和授权

Ron*_*Ron 7 api django url tastypie

我有以下资源:

class MyUserResource(resources.MongoEngineResource):

    class Meta:
        ...
        authentication = MyKeyAuthentication()
        authorization = ApiKeyAuthorization()

    def override_urls(self):
        return [...] 
Run Code Online (Sandbox Code Playgroud)

所有标准tastypie的API调用都通过身份验证和授权进行路由.但是所有自定义函数/ url(在我的override_urls中)都忽略了auth/auth函数......

有什么想法吗?

编辑:

也许问题是没有调用调度程序.问题仍然是为什么......以及我如何改变这种行为!

Ron*_*Ron 15

好的,最后我发现在自定义/覆盖我的网址时,我也会覆盖调用的标准行为wrap_view.这导致不调用dispatch负责检查 - auth方法.

所以我只是auth手动将-checks 放在我的函数中(如下所示):

self.is_authenticated(request)
self.is_authorized(request)
Run Code Online (Sandbox Code Playgroud)

希望这有助于其他绝望的tastypie开发人员:)

  • ``is_authorized``函数不再存在,对此问题感兴趣的人应该检查调度函数的工作原理:https://github.com/toastdriven/django-tastypie/blob/master/tastypie/resources.py#L470并根据他们的需求调整流程. (8认同)