Python Eve Framework身份验证未应用于选定的API

时间:2015-05-08 18:07:53

标签: python rest authentication eve

我在Python Eve中编写API,以实现我遵循Python Eve Authentication

所写文档的身份验证

我的身份验证类代码如下: -

__author__ = 'sappal'

from eve.auth import BasicAuth

class SampleAuth(BasicAuth):
  def check_auth(self, username, password, allowed_roles, resource, method):

    if method == 'GET' and resource == 'org':
      print "Inside GET Method for Org Resource"

    elif method == 'POST' and resource == 'org':
      print "Inside POST Method for Org Resource "

    elif method == 'GET' and resource == 'people':
      print "Inside GET Method for People Resource"

    elif method == 'POST' and resource == 'people':
      return True
    else:
      return username == 'admin' and password == 'secret'

正如代码所述,我正在对没有身份验证的人端点进行POST调用{这就是我打算做的},但是当我在人员端点上进行POST调用时[http://127.0.0.1:5000/people]

我收到以下回复

{"_status": "ERR", "_error"
     {
       "message": "Please provide proper credentials", 
       "code": 401
     }
}

我的请求有效负载是: -

[
  {
    'firstname': 'Tushar',
    'lastname': 'Sappal',
    'email': 'testemailaddresshurray@gmail.com',
    'phonenumber': 123456789,
    'userid': '',
    'password': 'testtushar'
  }
]

我正在动态生成用户ID,因此它不是在请求有效负载中传递的强制值。

请帮助并指导我,我做错了什么。

1 个答案:

答案 0 :(得分:1)

尝试为public_methods资源设置['POST']people(请参阅docs)。或者您可以设置PUBLIC_METHODS,但之后您将打开所有API端点的POST方法。