我正在尝试让“多重身份验证”在 Tasty Pie 中工作。到目前为止,ApiKeyAuthentication()可以进行外部调用,但是当我在自己的 Django 站点“ SessionAuthentication ”(托管 API 的同一站点)上使用 API 时,尽管用户已登录,但身份验证失败。
我错过了什么吗?
多认证的美味馅饼文档在这里
我的资源:
class CommonMeta:
"""
Based Mata to which all other model resources extend/inherit.
"""
# MultiAuthentication is used here, wraps any number of other authentication classes,
# attempting each until successfully authenticating.
authentication = MultiAuthentication(ApiKeyAuthentication(), SessionAuthentication())
authorization = UserObjectsOnlyAuthorization()
class ContactResource(MultipartResource, ModelResource):
class Meta(CommonMeta):
queryset = Contact.objects.all()
resource_name = 'contacts'
list_allowed_methods = ['get']
detail_allowed_methods = ['get', 'put', 'post']
excludes = ['id']
我的 AJAX 请求:
$.ajax({
url: '/api/v1/contacts/' + id + "/",
type: 'PUT',
data: {"company": "test"},
// On success.
success: function(data) {
alert('Load was performed.');
}
});
};