本文介绍了带有ApiKeyAuthentication的DeliciousPie和Django授权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在为此苦苦挣扎,浇了一堆其他的SO答案,但是似乎无法弄清楚如何使用ApiKeyAuthentication对我的Django站点进行用户身份验证.

I've been struggling with this for a bit, pouring over a bunch of other SO answers but can't seem to figure out how to authenticate a user to my Django site using the ApiKeyAuthentication.

在此答案中,接受的答案指出添加GET变量的用户名和api_key参数".我的问题是,如果DeliciousPie为我生成密钥,我怎么知道api密钥是什么?如果我想创建自己的 own 密钥,该将密钥放在哪里?

In this answer the accepted answer states "Add the username and api_key parameters to your GET variables". My question is, how do I know what the api key is, if TastyPie is generating the key for me? If I wanted to create my own key, where would I put that key?

这是我的api.py:

Here's my api.py:

class SystemResource(ModelResource):
  user = fields.ForeignKey(UserResource, 'user')

  class Meta:
    querySet = System.objects.all()
    resource_name = 'system'
    authentication = ApiKeyAuthentication()

当我调用URL: http://192.168.1.130:8080/systems/api/v1/user/?username=garfonzo&api_key=123456789 时,它失败,将我踢到登录名页.当然, 123456789 已经组成了,我没有在任何地方列出该密钥,因此从某些方面看,这很明显是失败的.

When I call the URL: http://192.168.1.130:8080/systems/api/v1/user/?username=garfonzo&api_key=123456789 it fails, kicking me to my login page. Of course, the 123456789 is quite made up, I have not listed that key anywhere so in some ways it's obvious this is failing).

在文档中,它讨论了授权标头,或在请求中提供用户名/api_ky.但是同样,如果我在请求中提供api_key,我怎么知道那个那个密钥应该是什么?它在服务器上的什么位置定义?

In the docs, it discusses either creating an Authorization header, or supplying the username/api_ky in the request. But again, if I'm supplying the api_key in the request, how do I know what that key should be? Where is it defined on the server?

有帮助吗?

推荐答案

为您的Deliciouspie创建一个API密钥,您应该转到管理网站,然后在DeliciousPie应用程序中添加一个新的API密钥.选择用户,将密钥留空,它将为您自动生成一个;)

In order to create an API Key for your Tastypie you should go to the Admin site, and in the TastyPie app, add a new API Key. Choose the user, leave the key blank, and it will autogenerate one for you ;)

这篇关于带有ApiKeyAuthentication的DeliciousPie和Django授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 16:00